Skip to content

Instantly share code, notes, and snippets.

@isuke
Last active August 29, 2015 14:00
Show Gist options
  • Save isuke/2f6c982fc83a59807b31 to your computer and use it in GitHub Desktop.
Save isuke/2f6c982fc83a59807b31 to your computer and use it in GitHub Desktop.
require 'thread'
THREAD_NUM = 4
list = ['*',
'_*',
'__*',
'___*',
'____*',
'_____*',
'______*',
'_______*',
'________*',
'_________*',]
locker = Mutex.new
list0 = list.dup
Array.new(THREAD_NUM) do
Thread.new do
while a = list0.shift
locker.synchronize do
# sleep 0.1
puts a
end
end
end
end.each(&:join)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment