Synchronization in thread
-
i have two thread running simul.. i want to access a same file from both thread and want to write data in that file..in synchronous manner..plz share code ..
Thanks in advance..
-
In my opinion, you could utilize "QMutexLocker":http://qt-project.org/doc/qt-5.0/qmutexlocker.html
inside write method. There is example how to use it on Qt documentation. -
@QMutex mutex;
thread1::run()
{
mutex.lock();// write data to the file
mutex.unlock();
}thread2::run()
{
mutex.lock();// write data to the file
mutex.unlock();
}@