Created
June 18, 2019 16:18
-
-
Save choallin/a5a211ccf2318440e54262f4a0e66e0e to your computer and use it in GitHub Desktop.
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
class DoorLock | |
def initialize(locked) | |
@locked = locked | |
@mutex = Mutex.new | |
end | |
def open? | |
@mutex.synchronize { !@locked } | |
end | |
def unlock! | |
unless open? | |
@mutex.synchronize do | |
puts "Opening the door!" | |
@locked = false | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment