I want multiple threads to all fire at the same time.
10.times do
Thread.new do
sleep rand(5) # Initialize all the stuff
wait_for_all_other_threads # Wait for other threads to initialize their stuff
fire! # Go.
end
end
How would I implement wait_for_all_other_threads so they all fire! at the same time?
Use a barrier sync: http://rubygems.org/gems/barrier/
A call to barrier will cause each thread to block until all of the threads have called it.