Add test demonstrating copying semaphore from parent to child.
This commit is contained in:
parent
16ceacb31e
commit
74acbae899
|
@ -1,7 +1,5 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
require 'mach/error'
|
require 'mach'
|
||||||
require 'mach/functions'
|
|
||||||
require 'mach/semaphore'
|
|
||||||
|
|
||||||
module Mach
|
module Mach
|
||||||
describe 'low level semaphore functions' do
|
describe 'low level semaphore functions' do
|
||||||
|
@ -30,5 +28,33 @@ module Mach
|
||||||
sem.wait
|
sem.wait
|
||||||
sem.destroy
|
sem.destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'coordinates access to shared resource between two tasks' do
|
||||||
|
sem = Semaphore.new(:value => 0)
|
||||||
|
|
||||||
|
port = Port.new
|
||||||
|
port.insert_right(:make_send)
|
||||||
|
Task.self.set_bootstrap_port(port)
|
||||||
|
|
||||||
|
child = fork do
|
||||||
|
parent_port = Task.self.get_bootstrap_port
|
||||||
|
Task.self.copy_send(parent_port)
|
||||||
|
# parent will copy send rights to sem into child task
|
||||||
|
sleep 0.5
|
||||||
|
sem.signal
|
||||||
|
Kernel.exit!
|
||||||
|
end
|
||||||
|
|
||||||
|
child_task_port = port.receive_right
|
||||||
|
|
||||||
|
start = Time.now.to_f
|
||||||
|
sem.insert_right(:copy_send, :ipc_space => child_task_port)
|
||||||
|
sem.wait
|
||||||
|
elapsed = Time.now.to_f - start
|
||||||
|
|
||||||
|
Process.wait child
|
||||||
|
|
||||||
|
elapsed.must be_gt(0.4)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue