Created
February 21, 2018 17:11
-
-
Save jqr/e352a33402149c56222c83f642fdbaec to your computer and use it in GitHub Desktop.
Easy to reason about linear overlapped execution of multiple threads to force contention for tests.
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" | |
# Easy to reason about linear overlapped execution of multiple threads to | |
# force contention for tests. | |
# | |
# -------- Time -------> | |
# Thread.current 1 ---------------------------------- 4 | |
# t2 2 ------- 3 | |
m = Mutex.new | |
cv = ConditionVariable.new | |
m.synchronize do | |
puts "1." | |
t2 = Thread.new do | |
m.synchronize do | |
puts "2." | |
cv.signal | |
puts "3." | |
end | |
end | |
cv.wait(m) | |
puts "4." | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment