Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compare-and-swap (CAS) command as a building block for synchronization primitives #5149

Open
elifarley opened this issue Nov 25, 2015 · 0 comments

Comments

@elifarley
Copy link

From Wikipedia article on CAS:

This operation is used to implement synchronization primitives like semaphores and mutexes, as well as more sophisticated lock-free and wait-free algorithms.

CAS will be useful in #5144 for instance.

Proposed syntax:

// When you want to use CAS for a few attributes only:
r.table("posts").get(1).update({
    title: r.compareAndSwap("Lorem ipsum OBSOLETUS", "Lorem ipsum NOVUS"),
    content: "Dolor sit amet"
})

// When you want to use CAS for many attributes:
r.table("posts").get(1).update( r.compareAndSwap(
{
    title: "Lorem ipsum OBSOLETUS",
    content: "Dolor sit amet OBSOLETUS"
}, {
    title: "Lorem ipsum NOVUS",
    content: "Dolor sit amet NOVUS"
}
))

This could be internally converted to something like

r.table("posts").get(1).update({
    title: r.branch(
      r.row('title').eq("Lorem ipsum OBSOLETUS"),
      "Lorem ipsum NOVUS",
      r.error(r.row('title')) // return an error indicating what was the unexpected value
    )
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants