Skip to content

Instantly share code, notes, and snippets.

@hayeah
Created March 31, 2010 16:48
Show Gist options
  • Select an option

  • Save hayeah/350562 to your computer and use it in GitHub Desktop.

Select an option

Save hayeah/350562 to your computer and use it in GitHub Desktop.
require 'thread'
queue = Queue.new
workers = 10.times.map do |i|
ts = Thread.new do
loop {
queue.pop.call
Thread.pass
}
end
end
loop {
# p [:size,queue.size]
Thread.pass unless queue.empty?
100.times do
queue << lambda {
# define work here
"work"
}
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment