Closed sticnarf closed 4 years ago
Why not just drain the queue when the last worker thread exits?
Why not just drain the queue when the last worker thread exits?
@BusyJay The hardest problem is not draining the existent tasks in the queue. It's to avoid wakers to push new tasks to the injector.
And a simple atomic read cannot avoid it completely. Because writing such a flag can happen between the check and pushing the task to the queue. That's why we need Weak
.
How about creating a WeakRemote for TaskCell that only contains weak pointer to remote? In such way, there will be no circular references. Although it still requires all Remotes and pools be dropped before releasing all the futures.
/cc @Little-Wallace can this solve your problem?
@BusyJay But one Remote
may be capture to a future.....
Yes. In my opinion, a thread pool hardly be shutdown and recreated during runtime. The library is designed under an assumption that threads are allowed to live long. We can try our best effort to avoid leak, but should optimize for the cases we focus.
How does it perform when using WeakRemote
?
How does it perform when using
WeakRemote
?
I update the benchmark result in the PR description. We don't have remote spawns via future notifies in the benchmark, so there is not much difference.
Closes #46
This PR makes
Remote
not hold a strong reference to the core and always check if the core is still alive before any operation.This adds extra cost that upgrades a weak ptr to a strong Arc.