-
Notifications
You must be signed in to change notification settings - Fork 50
Combined operator<<() isn't thread safe if used outside main thread #34
Comments
I notice it's worse than just early completing. It can lead to segfaults as well. If the future completes early, the main thread can end up deleting the combined future while the worker thread is about to call deleteLater on it. It seems because this line was added https://github.com/benlau/asyncfuture/blob/master/asyncfuture.h#L762 as part of #15. @vpicaver do you know why that change was made? |
That line does look suspicious. We should probably comment that line out and see if the testcases pass. |
That line forces the deferred to be moved to the main thread. The call to deleteLater needs an event loop to run correctly. It's not guaranteed that a QThread will have an event loop. |
Okay that makes sense. But by moving to the main thread, it makes deferred completion very racy. Here is an example of a crash I saw:
If the future completes and the shared pointer goes out of scope around the same time, the main thread and deleter race to delete the object. It was not a major issue before because it kept the deferred in the same thread. You can reproduce this trivially adding a small pause before invokeMethod(this, "deleteLater"). Any thoughts on how to fix it? |
@vpicaver Hello I would like to express my utmost gratitude to you for resolve the issues in this project. I've found that I don't have the time to continue the project's development or handling requests. Would you be interested in taking over the project? I will archive this repository and set a link to your repository. What do you think? @jsravn I think you should submit the PR to vpicaver's repository? |
Sure!
Phi|ip Sent from Gmail Mobile
…On Sat, Oct 14, 2023 at 8:23 AM Ben Lau ***@***.***> wrote:
@vpicaver <https://github.com/vpicaver> Hello
I would like to express my utmost gratitude to you for resolve the issues
in this project. I've found that I don't have the time to continue the
project's development or handling requests. Would you be interested in
taking over the project? I will archive this repository and set a link to
your repository. What do you think?
@jsravn <https://github.com/jsravn> I think you should submit the PR to
vpicaver's repository?
—
Reply to this email directly, view it on GitHub
<#34 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABKKDA6DZSOKUVXKFGLSYD3X7KVA5ANCNFSM4L47J22Q>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
An example of this issue is if two futures being added to Combined(). If future1 finished before future2 has been added, this will complete() the Combined(). Even though in this use case, we want the code below to print out "Finished!" once both future1 and future2 are finished. If future1 is finished before future2 is added, Finished() will be prematurely, called.
I don't think this can be easily be fixed without api changes to how Combine() is handled. Perhaps it better to advocate using async on the main thread only. The deferred needs to have a proper context object to make this work correrctly. By default deferred is move to the main thread.
The text was updated successfully, but these errors were encountered: