Qore Programming Language Reference Manual: Qore::Thread::AutoWriteLock Class Reference (original) (raw)
A helper class for the RWLock class for exception-safe write lock handling. More...
A helper class for the RWLock class for exception-safe write lock handling.
Restrictions:
AutoWriteLock objects, when used along with a RWLock object, allow Qore programmers to safely acquire and release a write lock, even if exceptions are thrown or return statements are executed in the block where the AutoWriteLock object is created.
AutoWriteLock objects are helper objects that acquire a write lock for the lifetime of the AutoWriteLock object. For this reason, it is normally only appropriate to assign an AutoWriteLock object to a local variable, so when the local variable goes out of scope, the AutoWriteLock object will be deleted and the write lock will be automatically released.
For example:
our RWLock rwl();
sub check_error(bool error) {
AutoWriteLock awl(rwl);
if (error) {
throw "ERROR", "sorry, an error happened";
}
return "OK";
}
Note
This class is not available with the PO_NO_THREAD_CLASSES parse option