Qore Programming Language Reference Manual
1.8.0
|
A helper class for the RWLock class for exception-safe read lock handling. More...
Public Member Methods | |
constructor (RWLock rwl) | |
Creates the AutoReadLock object based on the RWLock argument passed and immediately calls RWLock::readLock() More... | |
copy () | |
Throws an exception; objects of this class cannot be copied. More... | |
destructor () | |
Calls RWLock::readUnlock() on the saved RWLock and destroys the AutoReadLock object. More... | |
A helper class for the RWLock class for exception-safe read lock handling.
AutoReadLock objects, when used along with a RWLock object, allow Qore programmers to safely acquire and release a read lock, even if exceptions are thrown or return statements are executed in the block where the AutoReadLock object is created.
AutoReadLock objects are helper objects that acquire a read lock for the lifetime of the AutoReadLock object. For this reason, it is only appropriate to assign an AutoReadLock object to a local variable, so when the local variable goes out of scope, the AutoReadLock object will be deleted and the read lock will be automatically released.
For example:
Qore::Thread::AutoReadLock::constructor | ( | RWLock | rwl | ) |
Creates the AutoReadLock object based on the RWLock argument passed and immediately calls RWLock::readLock()
Creates the AutoReadLock object based on the RWLock argument passed. The AutoReadLock object immediately calls RWLock::readLock() on the RWLock object passed, and saves it so it can be released when the AutoReadLock object is destroyed.
THREAD-DEADLOCK | A deadlock was detected while trying to acquire the lock |
LOCK-ERROR | RWLock::readLock() called while already holding the write lock, object deleted in another thread, etc. |
Qore::Thread::AutoReadLock::copy | ( | ) |
Throws an exception; objects of this class cannot be copied.
AUTOREADLOCK-COPY-ERROR | objects of this class cannot be copied |
Qore::Thread::AutoReadLock::destructor | ( | ) |
Calls RWLock::readUnlock() on the saved RWLock and destroys the AutoReadLock object.
LOCK-ERROR | RWLock::readUnlock() called while not holding the read lock, RWLock object deleted in another thread, etc |