Created
July 18, 2019 08:48
-
-
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)
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
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