Skip to content

Instantly share code, notes, and snippets.

@markpapadakis
Last active December 22, 2015 01:39
Show Gist options
  • Select an option

  • Save markpapadakis/6397886 to your computer and use it in GitHub Desktop.

Select an option

Save markpapadakis/6397886 to your computer and use it in GitHub Desktop.
// 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