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 with Multiple Assignment? #92

Open
DavePearce opened this issue Jun 1, 2021 · 1 comment
Open

Compare and Swap with Multiple Assignment? #92

DavePearce opened this issue Jun 1, 2021 · 1 comment

Comments

@DavePearce
Copy link
Member

DavePearce commented Jun 1, 2021

An interesting question is whether or not we can already implement a compare and swap primitive with the existing syntax of Whiley. My angle of attack on this is to target the multiple assignment statement. Specifically, in a form like this:

A[i], A[j] = A[i], X

The key here is that, if i == j, then the above assigns X to A[i] otherwise A[i] is untouched. This is somehow a compare and set. We could have some definitions like this:

uint lock[NTHREADS]
uint HOLDER = 0
native uint THIS where THIS != HOLDER && THIS < NTHREADS

Don't quite know how to exploit this observation yet

@DavePearce
Copy link
Member Author

DavePearce commented Jun 1, 2021

Perhaps a minimal primitive would be an extended assignment statement:

x = e when c

Basically, the assignment either spinlocks until the condition is true (not very flexible) or just fails if the condition is not true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant