diff options
author | Eric Wong <normalperson@yhbt.net> | 2013-04-06 00:21:34 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2013-04-12 22:25:00 +0000 |
commit | 5bfc2dd29748c559e833ff654b5210067a1d9e91 (patch) | |
tree | c94af9ec25df5cba257d98f8a151d4a90763a8f0 | |
parent | 0f55aa0caa4846aab8e3a8df85fdea884a317a01 (diff) | |
download | sleepy_penguin-5bfc2dd29748c559e833ff654b5210067a1d9e91.tar.gz |
Concurrent modification of the array is not thread-safe.
-rw-r--r-- | test/test_epoll.rb | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/test/test_epoll.rb b/test/test_epoll.rb index 1e9a068..cd50cff 100644 --- a/test/test_epoll.rb +++ b/test/test_epoll.rb @@ -473,22 +473,26 @@ class TestEpoll < Test::Unit::TestCase nr = 10 nr.times do r, w = IO.pipe - pipes[r] = w + lock.synchronize { pipes[r] = w } @ep.add(r, Epoll::IN | Epoll::ET | Epoll::ONESHOT) t = Thread.new do sleep 2 events = 0 @ep.wait(maxevents) do |_,obj| - assert pipes.include?(obj), "#{obj.inspect} is unknown" - lock.synchronize { ok << obj } + lock.synchronize do + assert pipes.include?(obj), "#{obj.inspect} is unknown" + ok << obj + end events += 1 end events end thr << t end - pipes.each_value { |w| w.syswrite '.' } + lock.synchronize do + pipes.each_value { |w| w.syswrite '.' } + end thr.each do |t| begin t.run |