Skip to content

Instantly share code, notes, and snippets.

@danlynn
Created March 4, 2016 20:34
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 danlynn/183eaa73a7fceca499cd to your computer and use it in GitHub Desktop.
Save danlynn/183eaa73a7fceca499cd to your computer and use it in GitHub Desktop.
# imagine this code ran in parallel by 2 threads in the same proc
@@credit = params[:credit]
thread.sleep(1) # lots of work going on here giving other thread chance to set balance from its request
account.balance += @@credit # reading value that might have been set by either thread last
account.save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment