-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Use shared monitor with two interprocess_semaphore's #3648
Conversation
5713355
to
981639d
Compare
at the moment the solution can lead to a deadlock, because if the waiter is killed the |
5c1dbd9
to
44ddf49
Compare
After some attempts to implement a conditional variable via semaphores and waiters counter that can handled killed waiters, just get to similar as https://github.com/boostorg/interprocess/blob/develop/include/boost/interprocess/sync/spin/condition.hpp My suggest is not to use NIH implementation and fallback to the spinlock-based conditional variable via |
checked boost interprocess conditional variables on windows and osx: non-robust against application kills. will fallback on windows and osx to a solution with one semaphore that generates spurious wake ups for every killed |
eb504d4
to
215d7ce
Compare
215d7ce
to
0f2d93b
Compare
|
5e966f1
to
a97d2b9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some questions regarding readability, approach is fine. 👍
include/storage/shared_monitor.hpp
Outdated
#else | ||
template <typename Lock> void wait(Lock &lock) | ||
{ | ||
if (((internal().head + 1) & (buffer_size - 1)) == (internal().tail & (buffer_size - 1))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the advantage of using & (buffer_size - 1)
instead of % buffer_size
? I'm more familiar with the latter when it comes to wrap-a-round indexing.
Wrapping the ring buffer in smaller helper functions to hide the index "magic" might improve readability.
include/storage/shared_monitor.hpp
Outdated
while (internal().tail != internal().head) | ||
{ | ||
auto index = (internal().tail++) & (buffer_size - 1); | ||
auto semaphore = reinterpret_cast<bi::interprocess_semaphore *>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, getting the semaphore could be hidden behind a nicer interface.
include/storage/shared_monitor.hpp
Outdated
|
||
std::size_t head, tail; | ||
mutex_type mutex; | ||
char buffer[buffer_size * sizeof(bi::interprocess_semaphore)]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could warrant a little bit of an explanation of what we are going with these semaphore: Implementing a conditional variable using a queue of semaphores.
a97d2b9
to
8194776
Compare
@TheMarex i have moved queue functionality into the internal data structure. It is still has to be checked on OSX |
8194776
to
928e8fd
Compare
or a ring buffer with semaphores
928e8fd
to
e56a0b9
Compare
Checked |
Issue
One possible solution for #3633 is to use interprocess_semaphore's to model a conditional variable.
PR works for linux, windows, and OSX, but hits https://svn.boost.org/trac/boost/ticket/12617 boost bug on OS X 10.11. it can be fixed by the patch.
/cc @danpat, @TheMarex
Tasklist
Related:
#1221, #3558