Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'thread'
require 'open-uri'
LOCK = Mutex.new
$progress = 0
def thread_start
while true
open("http://www.microsoft.com/en/us/default.aspx") do |f|
f.read
end
inc_progress
end
end
def inc_progress
LOCK.synchronize do
1000.times do
File.open("/dev/null", "w") do |f|
f.write("hi")
end
end
end
LOCK.synchronize do
$progress += 1
puts "#{Thread.current.object_id.to_s(16)}: Progress = #{$progress}"
end
end
def start
threads = []
50.times do
thread = Thread.new do
thread_start
end
thread.abort_on_exception = true
threads << thread
end
threads.each do |thread|
thread.join
end
end
start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.