Anonymous user
Mutex: Difference between revisions
add Ruby
(→{{header|E}}: description change suggested by MarkM) |
(add Ruby) |
||
Line 199:
Mutex.unlock m;
=={{header|Ruby}}==
Ruby's standard library includes a <tt>mutex_m</tt> module that can be mixed-in
to a class.
<lang ruby>require 'mutex_m'
class SomethingWithMutex
include Mutex_m
...
end</lang>
Individual objects can be extended with the module too
<lang ruby>an_object = Object.new
an_object.extend(Mutex_m)</lang>
An object with mutex powers can then:
<lang ruby># acquire a lock -- block execution until it becomes free
an_object.mu_lock
# acquire a lock -- return immediately even if not acquired
got_lock = an_object.mu_try_lock
# have a lock?
if an_object.mu_locked? then ...
# release the lock
an_object.mu_unlock
# wrap a lock around a block of code -- block execution until it becomes free
an_object.my_synchronize do
do critical stuff
end</lang>
=={{header|Tcl}}==
|