-
Notifications
You must be signed in to change notification settings - Fork 67
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
blocking_get randomly does not return. #119
Comments
So far this is not a bug in the library, but a problem of the code. In the way as you call blocking get on all the futures, you can come into a dead lock situation on the thread pool. Sean Parent goes in detail into this problem in his talk: https://www.youtube.com/watch?v=QIHy8pXbneI at timestamp 1:18:00 The general recommendation is: Use never blocking_get! Use continuations wherever possible. I use blocking_get() only in test applications to ensure, that a single, final calculation is done and the program does not end, before that value is calculated. I recommend to change the code into the following by using the joining operation of when_all(). #include using namespace std; int main() {
return 0; |
I disagree.
I had tested the when_all before doing this more simple test. I know it works, but I wanted to do different tests. I still think this is a bug. |
I believe you are correct @FunMiles that this example is a bug. I'll try and investigate further this evening. However, we currently do not do task-promotion (immediate execution of the task on a get()). Task promotion can only be done for tasks that are scheduled on a non-serialized executor, and have no other tasks upon which they depend, unless all of those tasks can be promoted (for example, a task associated with a continuation has to also promote the task it is continuing). This is one reason why we don't have a generalized .get() but instead provide a blocking_get(). In order to use a blocking get (or wait) safely you have to know about the tasks that provide data to the future and we are trying to avoid systems that require non-local reasoning. We may add some form of promotion in the future, but only if we can do so without cost or through a more explicit API (make_promotable...). |
Status update - We hang waiting on the condition variable inside I've tried a few shots in the dark, setting |
Another odd data point - pausing in the debugger when it is stuck, and then continuing, will cause it to complete successfully (might cause a "spurious" wake on the condition variable - but still odd). |
Ahh... I believe I see the problem. After the lambda sets the flag to true, the function may exit before the condition variable is notified. In which case we notify a dead condition variable. However, because we are looping I think we end up notifying the condition variable that lands on the stack the next time around and then we are in a bad state... Looking into fixes. |
Okay - that is going to be a good example for a talk... moving the |
Great. Looking forward to pulling the fix. Michel Lesoinne |
Fixed in 1.2.0 |
Trying to get acquainted with the concurrency library, I tried the following code and it randomly gets stuck, even though the tasks associated with the futures all have been completed. Sometimes the executable will finish, sometimes it will not, staying stuck in one of the blocking_get(f).
Running on Mac OS X 10.12.6. Compiled with clang++ and C++17.
The text was updated successfully, but these errors were encountered: