Skip to content

Commit

Permalink
fix some possible hangs in threaded loops
Browse files Browse the repository at this point in the history
hopefully helps #32258
  • Loading branch information
JeffBezanson authored and KristofferC committed Jun 19, 2019
1 parent 5579bc6 commit 685a9e3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
15 changes: 9 additions & 6 deletions src/jl_uv.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ JL_DLLEXPORT void jl_uv_req_set_data(uv_req_t *req, void *data) { req->data = da
JL_DLLEXPORT void *jl_uv_handle_data(uv_handle_t *handle) { return handle->data; }
JL_DLLEXPORT void *jl_uv_write_handle(uv_write_t *req) { return req->handle; }

extern volatile unsigned _threadedregion;

JL_DLLEXPORT int jl_run_once(uv_loop_t *loop)
{
jl_ptls_t ptls = jl_get_ptls_states();
Expand All @@ -207,13 +209,14 @@ JL_DLLEXPORT int jl_run_once(uv_loop_t *loop)
JL_DLLEXPORT int jl_process_events(uv_loop_t *loop)
{
jl_ptls_t ptls = jl_get_ptls_states();
if (loop) {
if (loop && (_threadedregion || ptls->tid == 0)) {
jl_gc_safepoint_(ptls);
JL_UV_LOCK();
loop->stop_flag = 0;
int r = uv_run(loop,UV_RUN_NOWAIT);
JL_UV_UNLOCK();
return r;
if (jl_mutex_trylock(&jl_uv_mutex)) {
loop->stop_flag = 0;
int r = uv_run(loop,UV_RUN_NOWAIT);
JL_UV_UNLOCK();
return r;
}
}
return 0;
}
Expand Down
3 changes: 2 additions & 1 deletion src/partr.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,12 @@ JL_DLLEXPORT void jl_wakeup_thread(int16_t tid)
// get the next runnable task from the multiq
static jl_task_t *get_next_task(jl_value_t *getsticky)
{
jl_gc_safepoint();
jl_task_t *task = (jl_task_t*)jl_apply(&getsticky, 1);
if (jl_typeis(task, jl_task_type))
return task;
#ifdef JULIA_ENABLE_THREADING
jl_gc_safepoint();
return multiq_deletemin();
#else
return NULL;
Expand All @@ -273,7 +275,6 @@ JL_DLLEXPORT jl_task_t *jl_task_get_next(jl_value_t *getsticky)
jl_task_t *task;

while (1) {
jl_gc_safepoint();
task = get_next_task(getsticky);
if (task)
return task;
Expand Down

0 comments on commit 685a9e3

Please sign in to comment.