Created
July 11, 2019 17:59
-
-
Save delbetu/e707171c950ad756c4c1f3c9b49dde43 to your computer and use it in GitHub Desktop.
This file contains 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' | |
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