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

Queues based on Unsafe#getAndAdd instead of CAS spins? #226

Closed
felixbarny opened this issue Jan 4, 2019 · 4 comments
Closed

Queues based on Unsafe#getAndAdd instead of CAS spins? #226

felixbarny opened this issue Jan 4, 2019 · 4 comments

Comments

@felixbarny
Copy link

Hi,

I'm learning about lock-free and wait-free algorithms and I was asking myself whether queues could be implemented based on the wait-free Unsafe#getAndAdd method as opposed to the lock-free CAS spin. The latter can still lead to queuing effects, especially under high contention and when there are more threads than processors concurrently doing the CAS spin.

Example of a CAS spin in MpmcArrayQueue:

while (seq > pIndex || // another producer has moved the sequence(or +)
!casProducerIndex(pIndex, pIndex + 1)); // failed to increment

Would it be possible to restructure the algorithm to be wait-free or is that inherently impossible?

Thanks,
Felix

@franz1981
Copy link
Collaborator

@felixbarny
Copy link
Author

Cool, thanks for the link! Is there a paper or a presentation somewhere which explains the algorithm? Are there plans for an Mpmc variant?

@franz1981
Copy link
Collaborator

@felixbarny Not at short term, considering that this version is just experimental (even if quite stable now). @nitsanw maybe has something in mind, I can't say :)

Re the algorithm is commented and explained on the code and is a (now huge) variation of the Aeron publication log buffer: https://github.com/real-logic/aeron/wiki/Data-Structures.
Any differences from the orgiinal version introduced by me or @nitsanw are undocumented in any article/paper AFAIK, but the core design is quite similar to the Aeron original data structure.

@franz1981
Copy link
Collaborator

@felixbarny I suppose you should be interested into #230

franz1981 added a commit to franz1981/JCTools that referenced this issue Jan 20, 2019
franz1981 added a commit to franz1981/JCTools that referenced this issue Jan 20, 2019
franz1981 added a commit to franz1981/JCTools that referenced this issue Jan 20, 2019
franz1981 added a commit to franz1981/JCTools that referenced this issue Jan 21, 2019
franz1981 added a commit to franz1981/JCTools that referenced this issue Jan 21, 2019
franz1981 added a commit to franz1981/JCTools that referenced this issue Jan 21, 2019
franz1981 added a commit to franz1981/JCTools that referenced this issue Jan 21, 2019
franz1981 added a commit to franz1981/JCTools that referenced this issue Jan 21, 2019
franz1981 added a commit to franz1981/JCTools that referenced this issue Jan 21, 2019
franz1981 added a commit to franz1981/JCTools that referenced this issue Jan 21, 2019
franz1981 added a commit to franz1981/JCTools that referenced this issue Jan 21, 2019
franz1981 added a commit to franz1981/JCTools that referenced this issue Jan 22, 2019
franz1981 added a commit to franz1981/JCTools that referenced this issue Jan 23, 2019
@nitsanw nitsanw closed this as completed in b0febce Apr 6, 2019
franz1981 added a commit to franz1981/JCTools that referenced this issue May 22, 2019
franz1981 added a commit to franz1981/JCTools that referenced this issue May 22, 2019
franz1981 added a commit to franz1981/JCTools that referenced this issue May 22, 2019
franz1981 added a commit to franz1981/JCTools that referenced this issue May 22, 2019
franz1981 added a commit to franz1981/JCTools that referenced this issue May 23, 2019
franz1981 added a commit to franz1981/JCTools that referenced this issue May 26, 2019
franz1981 added a commit to franz1981/JCTools that referenced this issue May 29, 2019
nitsanw added a commit that referenced this issue Jul 16, 2019
Fixes #226: XADD mpmc queue: highly scalable queue
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

2 participants