{ vip_t::readlock r(vip); foo(r->n); } { vip_t::writelock w(vip); w->n=4; }
Read and write locks implement the typical ways of accessing a
very important object. As mentioned before,
x::vipobj
is lightweight, and not reference-
counted. Neither are these, and other kinds of locks. The underlying
very important object must remain in scope as long as any of its
outstanding locks remain in existence (their destructors release
internal locks within the very important object).
The x::vipobj::readlock
resolves to a constant
value of the very important object, and
x::vipobj::writelock
predictably resolves to
a mutable value. Both locks implement the
“*” and “->” operators that resolve to the
very important object's value.
Naturally, multiple x::vipobj::readlock
s
may exist concurrently, but only one
x::vipobj::writelock
at a time, which blocks
other
x::vipobj::writelock
s and other
x::vipobj::readlock
s.
A x::vipobj::writelock
does not invoke the
registered notification callbacks. Acquiring, using, and releasing
read and write locks merely
provide a means for modifications to the underlying very important object;
and are not reportable to notification handlers.