Skip to content

Instantly share code, notes, and snippets.

@choallin
Created June 18, 2019 16:18
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 choallin/a5a211ccf2318440e54262f4a0e66e0e to your computer and use it in GitHub Desktop.
Save choallin/a5a211ccf2318440e54262f4a0e66e0e to your computer and use it in GitHub Desktop.
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