1: #!/usr/bin/env ruby 2: 3: def lock(semaphore) 4: semaphore.lock 5: yield 6: ensure 7: semaphore.unlock 8: end