- Method
wait
void wait(Thread.MutexKey mutex_key)
void wait(Thread.MutexKey mutex_key, int(0..)|float seconds)
void wait(Thread.MutexKey mutex_key, int(0..) seconds, int(0..999999999) nanos)
- Description
Wait for condition.
This function makes the current thread sleep until the condition
variable is signalled or the timeout is reached.
- Parameter mutex_key
A Thread.MutexKey object for a Thread.Mutex . It will be
unlocked atomically before waiting for the signal and then
relocked atomically when the signal is received or the timeout
is reached.
- Parameter seconds
Seconds to wait before the timeout is reached.
- Parameter nanos
Nano (1/1000000000) seconds to wait before the timeout is reached.
This value is added to the number of seconds specified by seconds .
A timeout of zero seconds disables the timeout.
The thread that sends the signal should have the mutex locked
while sending it. Otherwise it's impossible to avoid races where
signals are sent while the listener(s) haven't arrived to the
wait calls yet.
- Note
The support for timeouts was added in Pike 7.8.121, which was
after the first public release of Pike 7.8.
- Note
Note that the timeout is approximate (best effort), and may
be exceeded if eg the mutex is busy after the timeout.
- Note
In Pike 7.2 and earlier it was possible to call wait()
without arguments. This possibility was removed in later
versions since it unavoidably leads to programs with races
and/or deadlocks.
- Note
Note also that any threads waiting on the condition will be
woken up when it gets destructed.
- See also
Mutex->lock()