Anonymous user
Mutex: Difference between revisions
added objective-c
(added objective-c) |
|||
Line 185:
<code>when</code> blocks and <code>Ref.whenResolved</code> return a ''promise'' for the result of the deferred action, so the mutex here waits for the gratuitously complicated increment to complete before becoming available for the next action.
=={{header|Objective-C}}==
<lang objc>NSLock *m = [[NSLock alloc] init];
[m lock]; // locks in blocking mode
if ([m tryLock]) { // acquire a lock -- does not block if not acquired
// lock acquired
} else {
}
[m unlock];</lang>
=={{header|OCaml}}==
OCaml provides a
It is very simple, there are four functions:
if (Mutex.try_lock m)
else ... (* already locked, do not block *)
▲ then ... (* did the lock *)
▲ else ... (* already locked, do not block *)
=={{header|Ruby}}==
|