Skip to content

Commit

Permalink
Added safe global counter example
Browse files Browse the repository at this point in the history
  • Loading branch information
mhakeem committed May 30, 2014
1 parent b8b9c38 commit e7ef1dd
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions safe_global_counter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require "thread"

class Counter
def initialize
@counter = 0
@mutex = Mutex.new
end

def incerement
@mutex.synchronize do
@counter += 1
end
end

end

$counter = Counter.new

0 comments on commit e7ef1dd

Please sign in to comment.