On mach, allow other ruby green threads to continue during semaphore wait
This commit is contained in:
parent
4906f5acf5
commit
d1644104c8
|
@ -72,8 +72,8 @@ module Mach
|
||||||
|
|
||||||
# Attach a function as with +attach_function+, but check the
|
# Attach a function as with +attach_function+, but check the
|
||||||
# return value and raise an exception on errors.
|
# return value and raise an exception on errors.
|
||||||
def self.attach_mach_function(sym, argtypes, rettype)
|
def self.attach_mach_function(sym, argtypes, rettype, options = nil)
|
||||||
attach_function(sym, argtypes, rettype)
|
attach_function(sym, argtypes, rettype, options)
|
||||||
error_check(sym)
|
error_check(sym)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -208,7 +208,8 @@ module Mach
|
||||||
:kern_return_t)
|
:kern_return_t)
|
||||||
attach_mach_function(:semaphore_wait,
|
attach_mach_function(:semaphore_wait,
|
||||||
[:semaphore_t],
|
[:semaphore_t],
|
||||||
:kern_return_t)
|
:kern_return_t,
|
||||||
|
:blocking => true)
|
||||||
attach_mach_function(:semaphore_timedwait,
|
attach_mach_function(:semaphore_timedwait,
|
||||||
[:semaphore_t, TimeSpec.val],
|
[:semaphore_t, TimeSpec.val],
|
||||||
:kern_return_t)
|
:kern_return_t)
|
||||||
|
|
|
@ -55,6 +55,26 @@ module ProcessShared
|
||||||
mem.get_char(0).must_equal(0)
|
mem.get_char(0).must_equal(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_allows_other_threads_within_a_process_to_continue_while_locked
|
||||||
|
was_set = false
|
||||||
|
|
||||||
|
@lock.synchronize do
|
||||||
|
t1 = Thread.new do
|
||||||
|
# give t2 a chance to wait on the lock, then set the flag
|
||||||
|
sleep 0.01
|
||||||
|
was_set = true
|
||||||
|
end
|
||||||
|
|
||||||
|
t2 = Thread.new do
|
||||||
|
@lock.synchronize { }
|
||||||
|
end
|
||||||
|
|
||||||
|
# t1 should set the flag and die while t2 is still waiting on the lock
|
||||||
|
t1.join
|
||||||
|
end
|
||||||
|
|
||||||
|
was_set.must_equal(true)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue