Qore Programming Language Reference Manual: Qore::Thread::AutoReadLock Class Reference (original) (raw)

A helper class for the RWLock class for exception-safe read lock handling. More...

A helper class for the RWLock class for exception-safe read lock handling.

Restrictions:

Qore::PO_NO_THREAD_CLASSES

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:

our RWLock rwl();

sub check_error(error) {

AutoReadLock arl(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