code_junkie

How to implement thread safe reference counting in C++

Nov 10th, 2011
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. do
  2. read the count
  3. perform mathematical operation
  4. interlockedcompareexchange( destination, updated count, old count)
  5. until the interlockedcompareexchange returns the success code.
  6.  
  7. a = b;
  8.  
  9. if (a != null)
  10. if (InterlockedDecrement(ref a.m_ref) == 0)
  11. a.FinalRelease();
  12.  
  13. if (b != null)
  14. InterlockedIncrement(ref b.m_ref);
  15.  
  16. a = b;
Add Comment
Please, Sign In to add comment