Project

General

Profile

Bug #2714 ยป deadlock.rb

A simple script to trigger the deadlock. - sf (s f), 02/06/2010 12:43 AM

 
# tested on ruby 1.9.1p243 (2009-07-16 revision 24175)
# deadlocks after a few seconds.

require 'thread'
require 'socket'

threads = []

s1, s2 = ::Socket.pair( ::Socket::AF_UNIX, ::Socket::SOCK_STREAM, 0 )

threads << ::Thread.new {
while( true )
p "Hello World!"
end
}

threads << ::Thread.new( s1 ) { | socket |
while( true )
s = ::IO.select( nil, [socket], nil, 0.2 )
if( s == nil || s[0] == nil )
next
end
sent = socket.syswrite( "A" * 8192 )
p "Sent #{sent} bytes."
end
}

threads << ::Thread.new( s2 ) { | socket |
while( true )
s = ::IO.select( [socket], nil, nil, 0.2 )
if( s == nil || s[0] == nil )
next
end
data = socket.sysread( 8192 )
p "Read #{data.length} bytes."
end
}

threads.each{ |t| t.join }
    (1-1/1)