Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
6
Task/Mutex/Ruby/mutex-1.rb
Normal file
6
Task/Mutex/Ruby/mutex-1.rb
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
require 'mutex_m'
|
||||
|
||||
class SomethingWithMutex
|
||||
include Mutex_m
|
||||
...
|
||||
end
|
||||
2
Task/Mutex/Ruby/mutex-2.rb
Normal file
2
Task/Mutex/Ruby/mutex-2.rb
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
an_object = Object.new
|
||||
an_object.extend(Mutex_m)
|
||||
16
Task/Mutex/Ruby/mutex-3.rb
Normal file
16
Task/Mutex/Ruby/mutex-3.rb
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue