Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pmatsinopoulos/a19c20b63c996f7a66652e947d4d181a to your computer and use it in GitHub Desktop.
Save pmatsinopoulos/a19c20b63c996f7a66652e947d4d181a to your computer and use it in GitHub Desktop.
Using Mutex to Give Work to Threads
user = User.find_by!(email: "[email protected]")
mutex = Thread::Mutex.new
threads = []
5.times do
threads << Thread.new do
CalculateUserBalanceJob.perform_now(user.id, mutex)
end
end
threads.each(&:join)
user.reload
puts "user_balance: #{user.user_balance.balance}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment