I was having trouble understanding exactly how lock() worked. I think I now understand thanks to a passage I came across on this page http://www.phy.ohiou.edu/cgi-bin/man-cg-…–unlock+3T
A critical section of code is enclosed by a the call to lock
the mutex and the call to unlock the mutex to protect it
from simultaneous access by multiple threads. Only one
thread at a time may possess mutually exclusive access to
the critical section of code that is enclosed by the mutex-
locking call and the mutex-unlocking call, whether the
mutex’s scope is intra-process or inter-process. A thread
calling to lock the mutex either gets exclusive access to
the code starting from the successful locking until its call
to unlock the mutex, or it waits until the mutex is unlocked
by the thread that locked it.
Perhaps something similar could be included in the annotations inside future versions of the example, or in documentation fr the add on.