Refactor class hierarchy, implementation selection details.
This commit is contained in:
1 parent
64b746a98c
commit
15fe2e5057
16 files changed
+100
-147
No files matched your search
+26
-22
@@ -30,31 +30,35 @@ module Mach
|
||||
end
|
||||
|
||||
it 'coordinates access to shared resource between two tasks' do
|
||||
sem = Semaphore.new(:value => 0)
|
||||
begin
|
||||
sem = Semaphore.new(:value => 0)
|
||||
|
||||
port = Port.new
|
||||
port.insert_right(:make_send)
|
||||
Task.self.set_bootstrap_port(port)
|
||||
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!
|
||||
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)
|
||||
ensure
|
||||
Task.self.set_bootstrap_port(Mach::Functions.bootstrap_port)
|
||||
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
|
||||
@@ -1,6 +1,5 @@
|
||||
require 'spec_helper'
|
||||
require 'process_shared/mutex'
|
||||
require 'process_shared/shared_memory'
|
||||
require 'process_shared'
|
||||
|
||||
module ProcessShared
|
||||
describe Mutex do
|
||||
@@ -60,9 +59,9 @@ module ProcessShared
|
||||
|
||||
pid = Kernel.fork do
|
||||
mutex.lock
|
||||
sleep 0.2
|
||||
mutex.unlock
|
||||
Kernel.exit!
|
||||
# sleep 0.2
|
||||
# mutex.unlock
|
||||
# Kernel.exit!
|
||||
end
|
||||
|
||||
sleep 0.1
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
require 'spec_helper'
|
||||
|
||||
require 'ffi'
|
||||
require 'process_shared/semaphore'
|
||||
require 'process_shared/shared_memory'
|
||||
require 'process_shared'
|
||||
|
||||
module ProcessShared
|
||||
describe Semaphore do
|
||||
|
||||
Reference in new issue
Block a user