have QThread something like volatile member in Java?

<>

This question already has an answer here:

Answers


Use QMutex with a QMutexLocker around your variable.

EDIT:

QMutex * mutex = new QMutex();
int shared_integer = 0;

void func1()
{
    int temp;    
    // lots of calculations
    temp = final_value_from_calculations;

    // about to save to the shared integer
    {
        QMutexLocker locker(mutex);// this thread waits until the mutex is unlocked.
        qDebug() << "Mutex is now locked!";
        // access the shared variable
        shared_integer = temp;

        // if you had some reason to return early here, the mutex locker would
        // unlock your putex for you properly!
        // return; // locker's destructor gets called and the mutex gets unlocked

    }// lockers's destructor gets called and the mutex gets unlocked
    qDebug() << "Mutex is now unlocked!";

}

void func2()
{
    QMutexLocker locker(mutex);
    qDebug() << shared_integer;
}

Need Your Help

generic method in abstract class

c# generics abstract-class

I have the following abstract base class in which i have an abstract method. I need to know how to implement this abstract method in the child classes. The problem is how do I declare a class whose...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.