Guest User

Untitled

a guest
Apr 25th, 2012
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. Why does __sync_add_and_fetch work for a 64 bit variable on a 32 bit system?
  2. value = dest;
  3. While(!CAS8B(&dest,value,value + 1))
  4. {
  5. value = dest;
  6. }
  7.  
  8. oldValue = *dest;
  9. do {
  10. newValue = oldValue+1;
  11. } while (!compare_and_swap(dest, &oldValue, newValue));
  12.  
  13. bool compare_and_swap (int *dest, int *oldVal, int newVal)
  14. {
  15. do atomically {
  16. if ( *oldVal == *dest ) {
  17. *dest = newVal;
  18. return true;
  19. } else {
  20. *oldVal = *dest;
  21. return false;
  22. }
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment