From 64bf5f0cdb6c67a55b83fee6eea53314dd24cc4c Mon Sep 17 00:00:00 2001 From: Ian Date: Sat, 19 Feb 2022 03:15:11 -0500 Subject: [PATCH 1/2] lock around outputting precompile statements --- src/gf.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/gf.c b/src/gf.c index fef3342b6b786..ad2691c18f239 100644 --- a/src/gf.c +++ b/src/gf.c @@ -1970,6 +1970,8 @@ jl_code_instance_t *jl_method_compiled(jl_method_instance_t *mi, size_t world) return NULL; } +jl_mutex_t precomp_statement_out_lock; + static void record_precompile_statement(jl_method_instance_t *mi) { static ios_t f_precompile; @@ -1980,6 +1982,7 @@ static void record_precompile_statement(jl_method_instance_t *mi) if (!jl_is_method(def)) return; + JL_LOCK(&precomp_statement_out_lock); if (s_precompile == NULL) { const char *t = jl_options.trace_compile; if (!strncmp(t, "stderr", 6)) { @@ -1998,6 +2001,7 @@ static void record_precompile_statement(jl_method_instance_t *mi) if (s_precompile != JL_STDERR) ios_flush(&f_precompile); } + JL_UNLOCK(&precomp_statement_out_lock); } jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t world) From d6ebcab09163d9e48c6c5eb19b09098aefa14626 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Sat, 19 Feb 2022 09:25:03 -0500 Subject: [PATCH 2/2] only lock if threading is possible --- src/gf.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/gf.c b/src/gf.c index ad2691c18f239..acd52c1913427 100644 --- a/src/gf.c +++ b/src/gf.c @@ -1982,7 +1982,8 @@ static void record_precompile_statement(jl_method_instance_t *mi) if (!jl_is_method(def)) return; - JL_LOCK(&precomp_statement_out_lock); + if (jl_n_threads > 1) + JL_LOCK(&precomp_statement_out_lock); if (s_precompile == NULL) { const char *t = jl_options.trace_compile; if (!strncmp(t, "stderr", 6)) { @@ -2001,7 +2002,8 @@ static void record_precompile_statement(jl_method_instance_t *mi) if (s_precompile != JL_STDERR) ios_flush(&f_precompile); } - JL_UNLOCK(&precomp_statement_out_lock); + if (jl_n_threads > 1) + JL_UNLOCK(&precomp_statement_out_lock); } jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t world)