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

queue empy / full check shouldn't be coded as pre-condition; instead it should return bool (success / fail) #3

Open
mw66 opened this issue May 15, 2020 · 0 comments

Comments

@mw66
Copy link

mw66 commented May 15, 2020

https://github.com/MartinNowak/lock-free/blob/master/src/lock_free/rwqueue.d#L29

    void push(shared(T) t)
    in { assert(!full); }
    body ...

https://github.com/MartinNowak/lock-free/blob/master/src/lock_free/rwqueue.d#L38

    shared(T) pop()
    in { assert(!empty); }
    body ...

They are public methods, the caller may call them at some unknown state, so it's the container's responsibility to behave correctly under any condition. The best way is return a bool indicate failure or success, instead of throw assertion exception (and only in debug mode).

The reference implementation in C++ used this returning bool policy too:

https://bitbucket.org/KjellKod/lock-free-wait-free-circularfifo/src/1dcdaa20158c69f280c64dc0a0f9b11f45983a29/src/circularfifo_memory_sequential_consistent.hpp#lines-65

https://bitbucket.org/KjellKod/lock-free-wait-free-circularfifo/src/1dcdaa20158c69f280c64dc0a0f9b11f45983a29/src/circularfifo_memory_sequential_consistent.hpp#lines-75

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