PDA

View Full Version : Write from multiple QThreads on one file



Malek
27th December 2010, 20:59
Hi,

Threads are running simultaneously and writing to the same file. When two threads write to the file in same time, The code will crash.

Is there any way to organize the writing without using temporary variables?

tbscope
27th December 2010, 21:01
Learn about mutexes

franz
27th December 2010, 21:02
Create an object that serializes the file access using a QMutex. Your threads can then access a single instance of that object.

Malek
27th December 2010, 21:23
Thanks tbscope ,Thanks franz
may I ask for an example.

Thanks in advance for your fast response.

tbscope
27th December 2010, 21:29
You may.

Note that it will go a lot faster if you search for yourself in the documentation first:
http://doc.qt.nokia.com/4.7/all-examples.html

Then you will find things like this:
http://doc.qt.nokia.com/4.7/threads-waitconditions.