Skip to content

Instantly share code, notes, and snippets.

@begin29
Created July 18, 2019 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save begin29/8ad4027b73b3dec96ba09afeceed96cc to your computer and use it in GitHub Desktop.
Save begin29/8ad4027b73b3dec96ba09afeceed96cc to your computer and use it in GitHub Desktop.
in line 7 sometimes will be [...true, false...] values because that is not within synchronize block (line 8)
mutex = Mutex.new
flags = [false, false, false, false, false, false, false, false, false, false]
threads = 50.times.map do
Thread.new do
100000.times do
puts flags.to_s
mutex.synchronize do
flags.map! { |f| !f }
end
end
end
end
threads.each(&:join)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment