Extracted from Pike v7.4 release 341 at 2005-11-21.
pike.ida.liu.se
[Top]
predef::
Thread
Thread.Mutex

Method Thread.Mutex()->lock()


Method lock

MutexKey lock()
MutexKey lock(int type)

Description

This function attempts to lock the mutex. If the mutex is already locked by a different thread the current thread will sleep until the mutex is unlocked. The value returned is the 'key' to the lock. When the key is destructed or has no more references the mutex will automatically be unlocked.

The type argument specifies what lock() should do if the mutex is already locked by this thread:

0

Throw an error.

1

Sleep until the mutex is unlocked. Useful if some other thread will unlock it.

2

Return zero. This allows recursion within a locked region of code, but in conjunction with other locks it easily leads to unspecified locking order and therefore a risk for deadlocks.


See also

trylock()