Skip to content

Instantly share code, notes, and snippets.

@semaperepelitsa
Created January 17, 2015 19:54
Show Gist options
  • Save semaperepelitsa/8b81f77f6ad894099e2d to your computer and use it in GitHub Desktop.
Save semaperepelitsa/8b81f77f6ad894099e2d to your computer and use it in GitHub Desktop.
require "thread"
mutex = Mutex.new
i = 0
while true
i += 1
Thread.new(i) do |n|
mutex.synchronize do
puts "#{n}. started request"
Thread.new(n) do |n|
puts "#{n}. started background"
sleep 10
puts "#{n}. finished background"
end
sleep 1
puts "#{n}. finished request"
end
end
sleep 2
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment