Skip to content

Instantly share code, notes, and snippets.

@lamont-granquist
Created October 30, 2021 19:44
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 lamont-granquist/39409838626b22433f8bf1878276b3c1 to your computer and use it in GitHub Desktop.
Save lamont-granquist/39409838626b22433f8bf1878276b3c1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require "async"
class Global
class << self
attr_accessor :counter
def counter
@counter ||= 0
end
end
end
Async do |task|
1000.times do
task.async do
val = Global.counter
sleep 0.0001
val += 1
Global.counter = val
end
end
end
puts Global.counter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment