Skip to content

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

@felixbarny

Description

@felixbarny

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions