https://github.com/JuliaLang/julia
Revision f36edc2c2429140663baeedddd4cf11712c4469d authored by Keno Fischer on 19 February 2020, 18:20:48 UTC, committed by GitHub on 19 February 2020, 18:20:48 UTC
When there is no work to do, the first thread to be idle will attempt to
run the event loop once, waiting for any notifications (which will usually
create new work). However, there is an interesting corner case where a
notification arrives, but no work was scheduled. That doesn't usually happen,
but there are a few situations where it does:

1) Somebody used a libuv primitive outside of julia, so the callback
   doesn't schedule any julia work.
2) Another thread forbily interrupted the waiting thread because it wants to
   take over the event loop for various reasons
3) On Windows, we occasionally get spurious wake ups of the event loop.

The existing code in partr assumed that we were in situation 2, i.e. that
there was another thread waiting to take over the event loop, so it released
the event loop and simply put the current thread to sleep in the expectation
that another thread will pick it up. However, if we instead are in one of the
other two conditions, there may not be another thread there to pick up the event
loop. Thus, with no thread owning the event loop, julia will stop responding to
events and effectively deadlock. Since both 1 and 3 are rare, and we don't actually
enter the event loop until there was no work for 4 milliseconds (which is fairly rare),
this condition rarely happens, but is occasionally observable on Windows, where it
caused #34769. To test that this fix works, we manually create situation 1 in the
test by creating an idle callback, which will prevent the event loop from blocking,
but only schedules julia work after it's been called 100 times. This reproduces
the observed failure from the issue and is fixed by this PR.

Fixes #34769

Co-authored-by: Jeff Bezanson <jeff@juliacomputing.com>
Co-authored-by: Jameson Nash <jameson@juliacomputing.com>
1 parent 4188b2c
History
Tip revision: f36edc2c2429140663baeedddd4cf11712c4469d authored by Keno Fischer on 19 February 2020, 18:20:48 UTC
partr: Fix deadlock (#34807)
Tip revision: f36edc2
File Mode Size
base
contrib
deps
doc
etc
src
stdlib
test
ui
.appveyor.yml -rw-r--r-- 2.1 KB
.gitattributes -rw-r--r-- 65 bytes
.gitignore -rw-r--r-- 273 bytes
.mailmap -rw-r--r-- 11.0 KB
.travis.yml -rw-r--r-- 6.1 KB
CITATION.bib -rw-r--r-- 2.6 KB
CONTRIBUTING.md -rw-r--r-- 21.4 KB
HISTORY.md -rw-r--r-- 275.6 KB
LICENSE.md -rw-r--r-- 5.0 KB
Make.inc -rw-r--r-- 41.0 KB
Makefile -rw-r--r-- 27.1 KB
NEWS.md -rw-r--r-- 4.1 KB
README.md -rw-r--r-- 6.2 KB
VERSION -rw-r--r-- 10 bytes
sysimage.mk -rw-r--r-- 3.8 KB

README.md

back to top