From GridLAB-D Wiki
gld_rlock - Module scope read lock Template:NEW30
Synopsis
gld_rlock(OBJECT*);
Description
Scope read locks on objects may be taken using the gld_rlock class. As long as the lock is in scope, the object remain read-locked. When the lock goes out of scope the object is unlocked.
Example
The following example implements a scope read-lock for an if-else statement, thereby avoiding multiple unlock calls for each return.
int example (int test)
{
gld_rlock _lock(my);
// object is now read-locked
if ( test==1 ) return 1;
else if ( test==2 ) return 2;
else if ( test==3 ) return 3;
else return 0;
// object unlocks automatically on return
}
Caveat
Be careful not to use general purpose accessors inside scope locks. This will cause a deadlock.
Version
Scope locks are supported as of Hassayampa (Version 3.0).