Created
May 12, 2017 00:13
-
-
Save SamSaffron/57018ae8bf8fbf6353d23714baf4633a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'thread' | |
mutex = Mutex.new | |
10000.times do |i| | |
r,w = IO.pipe | |
t = Thread.new { | |
begin | |
loop do | |
c = r.getc | |
break if c == '!' | |
end | |
# you need this, so you don't shut down the socket prior to print being fully handled | |
mutex.synchronize do | |
r.close | |
w.close | |
end | |
rescue => e | |
p e | |
end | |
} | |
mutex.synchronize do | |
w.print '!' | |
end | |
t.join | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment