Guest User

Untitled

a guest
Jun 23rd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. int a = *MemoryLocationOne;
  2. memory_fence();
  3. int b = *MemoryLocationTwo;
  4. return (a + b) == 0;
  5.  
  6. memory_fence_start();
  7. int a = *MemoryLocationOne;
  8. int b = *MemoryLocationTwo;
  9. int test = (a + b) == 0;
  10. memory_fence_stop();
  11.  
  12. return test;
  13.  
  14. // Skipping ensuring padding.
  15. union Data
  16. {
  17. struct members
  18. {
  19. int a;
  20. int b;
  21. };
  22.  
  23. LONGLONG _64bitData;
  24. };
  25.  
  26. Data* data;
  27.  
  28.  
  29. Data captured;
  30.  
  31. do
  32. {
  33. captured = *data;
  34. int result = captured.members.a + captured.members.b;
  35. } while (InterlockedCompareExchange64((LONGLONG*)&data->_64bitData,
  36. captured._64BitData,
  37. captured._64bitData) != captured._64BitData);
  38.  
  39. data->members.a = 0;
  40. fence();
  41.  
  42. data->members.b = 0;
  43. fence();
  44.  
  45. int captured = data->members.a;
  46.  
  47. int captured = data->members.b;
  48.  
  49. // all reads...
  50. lock(lockProtectingAllAccessToMemoryOneAndTwo)
  51. {
  52. a = *MemoryLocationOne;
  53. b = *MemoryLocationTwo;
  54. }
  55.  
  56. // all writes...
  57. lock(lockProtectingAllAccessToMemoryOneAndTwo)
  58. {
  59. *MemoryLocationOne = someValue;
  60. *MemoryLocationTwo = someOtherValue;
  61. }
Add Comment
Please, Sign In to add comment