Skip to content

Instantly share code, notes, and snippets.

@delbetu
Created July 11, 2019 17:59
Show Gist options
  • Save delbetu/e707171c950ad756c4c1f3c9b49dde43 to your computer and use it in GitHub Desktop.
Save delbetu/e707171c950ad756c4c1f3c9b49dde43 to your computer and use it in GitHub Desktop.
require 'thread'
params_for_job = Queue.new
workers = []
def perform_task(params_for_job)
while x = params_for_job.pop
print x + "\n"
end
return x
end
30.times do |i|
params_for_job.push("a"*i)
end
4.times do
workers << Thread.new do
x = perform_task(params_for_job)
end
end
workers.map { |thr| thr.join(1) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment