Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-1.2] fix some possible hangs in threaded loops #32352

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -243,9 +243,11 @@ JL_DLLEXPORT void jl_enqueue_task(jl_task_t *task)
// 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;
jl_gc_safepoint();
return multiq_deletemin();
}

Expand All @@ -258,7 +260,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