![]() |
PIP 5.6.1
Platform-Independent Primitives
|
Synchronization primitive that allows concurrent readers and exclusive writer access. More...
#include <pireadwritelock.h>
Public Member Functions | |
| PIReadWriteLock | PIReadWriteLock () |
| Constructs PIReadWriteLock. | |
| ~PIReadWriteLock () | |
| Destroy PIReadWriteLock. | |
| void | lockWrite () |
| Acquires writer access, waiting until there are no active readers or writer. | |
| bool | tryLockWrite () |
| Tries to acquire writer access without waiting. | |
| bool | tryLockWrite (PISystemTime timeout) |
| Tries to acquire writer access within timeout. | |
| void | unlockWrite () |
| Releases writer access and wakes waiting threads. | |
| void | lockRead () |
| Acquires one reader slot, waiting while writer access is active. | |
| bool | tryLockRead () |
| Tries to acquire reader access without waiting. | |
| bool | tryLockRead (PISystemTime timeout) |
| Tries to acquire reader access within timeout. | |
| void | unlockRead () |
| Releases one reader slot and wakes waiting threads. | |
Synchronization primitive that allows concurrent readers and exclusive writer access.
Read/Write lock.
PIReadWriteLock provides more complex critical code section defence between several threads. PIReadWriteLock permit only one thread to modify data, besides multiple thread can read data simultaneously. Conatains methods: lockWrite(), tryLockWrite(), unlockWrite(), lockRead(), tryLockRead() and unlockRead().
For automatic read and write locks use PIReadLocker and PIWriteLocker.
When one thread lock for write with lockWrite(), all other threads (read and write) can`t access data until this thread call unlockWrite(). In this way, write lock works similar to mutex.
On the other hand, several threads can simultaneously read data. In other words, lockRead() increase read threads counter and unlockRead() decrease. But thread can`t read data while other thread locked for write.