From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS47066 71.19.144.0/20 X-Spam-Status: No, score=-1.9 required=3.0 tests=AWL,BAYES_00 shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: normalperson@yhbt.net Received: from zedshaw2.xen.prgmr.com (zedshaw2.xen.prgmr.com [71.19.156.177]) by dcvr.yhbt.net (Postfix) with ESMTP id 295071F6C0 for ; Thu, 11 Apr 2013 04:18:14 +0000 (UTC) Received: from zedshaw2.xen.prgmr.com (unknown [IPv6:::1]) by zedshaw2.xen.prgmr.com (Postfix) with ESMTP id F407573DF4 for ; Thu, 11 Apr 2013 04:18:43 +0000 (UTC) MIME-Version: 1.0 Date: Thu, 11 Apr 2013 04:17:31 +0000 From: Eric Wong List-Archive: List-Help: List-Id: List-Post: List-Subscribe: List-Unsubscribe: Message-Id: <1365653855-1101-3-git-send-email-normalperson@yhbt.net> Precedence: list References: <1365653855-1101-1-git-send-email-normalperson@yhbt.net> Sender: sleepy.penguin@librelist.org Subject: [sleepy.penguin] [PATCH 2/6] test_epoll: synchronize writes to the pipe array To: sleepy.penguin@librelist.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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