Momergil
29th May 2014, 18:54
Hello!
I have implemented an application where, apart from the main thread, there are two other threads that access the same QVector: one only writes into it while the other reads and erase (QVector::clear()). In order to prevent problems, I created a QReadWriteLock on each of the two classes and I call them when needed (either for "lockForWrite()" in the first thread or "lockForRead()" in the second).
The problem is that, while debugging, I found out that after calling the lockForRead() and inside its scope the QVector was actually being edited by the first thread (which had itself called lockForWrite() before doing that). In other words, the locking wasn't working \o/
So does this means that, in order for the locking mechanism to work, I need to always consider the same locker? In other words, I must either declare one of the lockers as public and access it from the other thread or else use "extern" to access it? And is this valid also for mutexes?
Thanks,
Momergil
I have implemented an application where, apart from the main thread, there are two other threads that access the same QVector: one only writes into it while the other reads and erase (QVector::clear()). In order to prevent problems, I created a QReadWriteLock on each of the two classes and I call them when needed (either for "lockForWrite()" in the first thread or "lockForRead()" in the second).
The problem is that, while debugging, I found out that after calling the lockForRead() and inside its scope the QVector was actually being edited by the first thread (which had itself called lockForWrite() before doing that). In other words, the locking wasn't working \o/
So does this means that, in order for the locking mechanism to work, I need to always consider the same locker? In other words, I must either declare one of the lockers as public and access it from the other thread or else use "extern" to access it? And is this valid also for mutexes?
Thanks,
Momergil