sleepy_penguin RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: sleepy.penguin@librelist.org
Subject: [sleepy.penguin] [PATCH 2/6] test_epoll: synchronize writes to the pipe array
Date: Thu, 11 Apr 2013 04:17:31 +0000	[thread overview]
Message-ID: <1365653855-1101-3-git-send-email-normalperson@yhbt.net> (raw)
In-Reply-To: 1365653855-1101-1-git-send-email-normalperson@yhbt.net

Concurrent modification of the array is not thread-safe.
---
 test/test_epoll.rb | 12 ++++++++----
 1 file 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 @@ def test_wait_one_event_per_thread
     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
-- 
1.8.2.279.g631bc94



  parent reply	other threads:[~2013-04-11  4:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-11  4:17 [sleepy.penguin] [PATCH 0/6] epoll wrapper cleanups Eric Wong
2013-04-11  4:17 ` [sleepy.penguin] [PATCH 1/6] test_epoll: fix timing error in test Eric Wong
2013-04-11  4:17 ` Eric Wong [this message]
2013-04-11  4:17 ` [sleepy.penguin] [PATCH 3/6] split Epoll and Epoll::IO, rewrite Epoll in Ruby Eric Wong
2013-04-12 20:38   ` Eric Wong
2013-04-11  4:17 ` [sleepy.penguin] [PATCH 4/6] epoll: implement thread-safety for mark/flag arrays Eric Wong
2013-04-12 21:18   ` Eric Wong
2013-04-11  4:17 ` [sleepy.penguin] [PATCH 5/6] epoll: cache alignment for per-thread structure Eric Wong
2013-04-11  4:17 ` [sleepy.penguin] [PATCH 6/6] avoid ENOMEM checking in common code paths Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/sleepy_penguin/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1365653855-1101-3-git-send-email-normalperson@yhbt.net \
    --to=normalperson@yhbt.net \
    --cc=sleepy.penguin@librelist.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhbt.net/sleepy_penguin.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).