![]() |
PIP 5.5.3
Platform-Independent Primitives
|
Read/Write lock. More...
#include <pireadwritelock.h>
Public Member Functions | |
| PIReadWriteLock | PIReadWriteLock () |
| Constructs PIReadWriteLock. | |
| ~PIReadWriteLock () | |
| Destroy PIReadWriteLock. | |
| void | lockWrite () |
| Lock for write. If already locked for write or read, than wait until all locks released. | |
| bool | tryLockWrite () |
| Try to lock for write. Returns if operation was successfull. | |
| bool | tryLockWrite (PISystemTime timeout) |
| Try to lock for write for "timeout". Returns if operation was successfull (timeout has not expired). | |
| void | unlockWrite () |
| Release lock for write. | |
| void | lockRead () |
| Lock for read. If already locked for write, than wait until write lock released. | |
| bool | tryLockRead () |
| Try to lock for read. Returns if operation was successfull. | |
| bool | tryLockRead (PISystemTime timeout) |
| Try to lock for read for "timeout". Returns if operation was successfull (timeout has not expired). | |
| void | unlockRead () |
| Release lock for read. | |
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.