diff --git a/src/julia.h b/src/julia.h index a7e0c1b2db17b..5b33974075bb7 100644 --- a/src/julia.h +++ b/src/julia.h @@ -20,6 +20,7 @@ #include "libsupport.h" #include #include +#include #include "htable.h" #include "arraylist.h" @@ -2228,6 +2229,9 @@ typedef struct _jl_task_t { uint16_t priority; // hidden state: + // cached floating point environment + // only updated at task switch + fenv_t fenv; // id of owning thread - does not need to be defined until the task runs _Atomic(int16_t) tid; diff --git a/src/task.c b/src/task.c index a1e8dabb89f9d..6320b206967b6 100644 --- a/src/task.c +++ b/src/task.c @@ -503,6 +503,8 @@ JL_NO_ASAN static void ctx_switch(jl_task_t *lastt) jl_set_pgcstack(&t->gcstack); jl_signal_fence(); lastt->ptls = NULL; + fegetenv(&lastt->fenv); + fesetenv(&t->fenv); #ifdef MIGRATE_TASKS ptls->previous_task = lastt; #endif @@ -1129,6 +1131,7 @@ JL_DLLEXPORT jl_task_t *jl_new_task(jl_function_t *start, jl_value_t *completion t->excstack = NULL; t->started = 0; t->priority = 0; + fegetenv(&t->fenv); jl_atomic_store_relaxed(&t->tid, t->copy_stack ? jl_atomic_load_relaxed(&ct->tid) : -1); // copy_stacks are always pinned since they can't be moved t->threadpoolid = ct->threadpoolid; t->ptls = NULL;