Go to the first, previous, next, last section, table of contents.


withLockDo

Control-struct: withLockDo{ ... }
file: job.t
package: muf
status: alpha

The withLockDo{...} operator is the main Muq MUF explicit synchronization mechanism: The canonical code for sequencing access to a small db by multiple jobs is

makeIndex --> obj      ( Create db object proper.              )
makeLock --> obj.lock  ( Create a lock (semaphore) for db.     )
...                     (                                       )
obj.lock withLockDo{   ( Block until we aquire the lock.       )
    ...                 ( Fiddle with the db.                   )
}                       ( Release the lock.                     )

See section Class Lock. See section popLockframe. See section pushLockframe.

Note that Muq streams provide implicit synchronization. See section Class MessageStream.

Fine point: Attempting to acquire a lock which the job already holds is essentially a no-op: Execution continues without pause. The only effect is that a null stackframe is pushed, to keep the subsequent popLockframe instruction happy.

Fine point: Since the point of a lock is that it can be held by only one job at a time, when a job holding a lock does a copyJob, only one of the resulting two jobs should hold the lock. By default, this will be the parent. If you wish to specify which job should inherit the lock, you may use the syntax

withChildLockDo{ ... }

to specify that the child should inherit the lock, or

withParentLockDo{ ... }

to specify that the parent should inherit the lock. Currently, withLockDo{ is a synonym for withParentLockDo{.


Go to the first, previous, next, last section, table of contents.