Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int a = *MemoryLocationOne;
- memory_fence();
- int b = *MemoryLocationTwo;
- return (a + b) == 0;
- memory_fence_start();
- int a = *MemoryLocationOne;
- int b = *MemoryLocationTwo;
- int test = (a + b) == 0;
- memory_fence_stop();
- return test;
- // Skipping ensuring padding.
- union Data
- {
- struct members
- {
- int a;
- int b;
- };
- LONGLONG _64bitData;
- };
- Data* data;
- Data captured;
- do
- {
- captured = *data;
- int result = captured.members.a + captured.members.b;
- } while (InterlockedCompareExchange64((LONGLONG*)&data->_64bitData,
- captured._64BitData,
- captured._64bitData) != captured._64BitData);
- data->members.a = 0;
- fence();
- data->members.b = 0;
- fence();
- int captured = data->members.a;
- int captured = data->members.b;
- // all reads...
- lock(lockProtectingAllAccessToMemoryOneAndTwo)
- {
- a = *MemoryLocationOne;
- b = *MemoryLocationTwo;
- }
- // all writes...
- lock(lockProtectingAllAccessToMemoryOneAndTwo)
- {
- *MemoryLocationOne = someValue;
- *MemoryLocationTwo = someOtherValue;
- }
Add Comment
Please, Sign In to add comment