Lock
sys.thread.Lock (Class)
A Lock allows blocking execution until it has been unlocked. It keeps track
of how often release has been called, and blocks exactly as many wait
calls.
The order of the release and wait calls is irrelevant. That is, a Lock
can be released before anyone waits for it. In that case, the wait call
will execute immediately.
Usage example:
var lock = new Lock();
var elements = [1, 2, 3];
for (element in elements) {
// Create one thread per element
new Thread(function() {
trace(element);
Sys.sleep(1);
// Release once per thread = 3 times
lock.release();
});
}
for (_ in elements) {
// Wait 3 times
lock.wait();
}
trace("All threads finished");
Instance Members
Waits for the lock to be released, or timeout (in seconds)
to expire. Returns true if the lock is released and false
if a time-out occurs.
| Name | Type | Default |
|---|---|---|
timeout |
Float | -1 |
| Returns |
|---|
| Bool |
new(): VoidCreates a new Lock which is initially locked.
Private Members
l: Dynamic