Skip to content

Commit

Permalink
Add JULIA_THREAD_SLEEP_THRESHOLD environment variable (JuliaLang#42981)
Browse files Browse the repository at this point in the history
This patch re-introduces the code originally added in
4752908 and was removed in
93e3d28.
  • Loading branch information
tkf committed Nov 8, 2021
1 parent 12b9bec commit ca28619
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/partr.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ extern "C" {

// thread sleep state

// default to DEFAULT_THREAD_SLEEP_THRESHOLD; set via $JULIA_THREAD_SLEEP_THRESHOLD
uint64_t sleep_threshold;

// thread should not be sleeping--it might need to do work.
static const int16_t not_sleeping = 0;

Expand Down Expand Up @@ -234,6 +237,15 @@ void jl_init_threadinginfra(void)
/* initialize the synchronization trees pool and the multiqueue */
multiq_init();

sleep_threshold = DEFAULT_THREAD_SLEEP_THRESHOLD;
char *cp = getenv(THREAD_SLEEP_THRESHOLD_NAME);
if (cp) {
if (!strncasecmp(cp, "infinite", 8))
sleep_threshold = UINT64_MAX;
else
sleep_threshold = (uint64_t)strtol(cp, NULL, 10);
}

jl_ptls_t ptls = jl_current_task->ptls;
jl_install_thread_signal_handler(ptls);
uv_mutex_init(&ptls->sleep_lock);
Expand Down Expand Up @@ -324,7 +336,7 @@ static int sleep_check_after_threshold(uint64_t *start_cycles)
return 0;
}
uint64_t elapsed_cycles = jl_hrtime() - (*start_cycles);
if (elapsed_cycles >= DEFAULT_THREAD_SLEEP_THRESHOLD) {
if (elapsed_cycles >= sleep_threshold) {
*start_cycles = 0;
return 1;
}
Expand Down

0 comments on commit ca28619

Please sign in to comment.