Last active
December 22, 2015 01:39
-
-
Save markpapadakis/6397886 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Update operation | |
| for (;;) | |
| { | |
| struct Ring *const cur = theRing, *const n = cur->Clone(); | |
| n->Update(…); | |
| n->AnotherUpdate(...); | |
| if (cas(&theRing, cur, n)) | |
| { | |
| Autorelease(cur); | |
| break; | |
| } | |
| else | |
| n->Release() | |
| } | |
| // Read operations access theRing directly; no need to lock | |
| // If a read operation can potentially take too long, we can retain and release it just to be on the safe side, like so: | |
| struct Ring *const r = theRing; | |
| r->Retain(); | |
| // Do something that takes too long | |
| r->Release(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment