You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The moral of the story? Don't create such circular deadlocks!
417
432
418
-
Beside trying to avoid deadlocks by all mean is the obvious suggestion and solution, the *blocking* part of the equation is what makes the presented exchange not possible.
433
+
How?
419
434
420
-
However, if the *main* task does not need to block the *worker* while executing, we can rewrite that code as such:
435
+
The mutually blocking calls cause the deadlock, so simply don't block.
421
436
422
-
On the *main* thread, let's instead assume this code:
437
+
For example, on the main thread, let's instead assume this code:
This way it's still possible to consume *worker* exposed utilities within *main* exposed tasks and the worker can happily unlock itself and react to any scheduled task in the meantime.
439
-
453
+
By scheduling the call to the worker (rather than awaiting it), it's possible
454
+
for the main thread to call functions defined in the worker in a non-blocking
455
+
manner, thus allowing the worker to also work in an unblocked manner and react
456
+
to such calls. We have resolved the mutual deadlock.
0 commit comments