Skip to content

Commit df1a3fc

Browse files
committed
fix #33338, race condition in triggering method compilation
1 parent 08d1fe6 commit df1a3fc

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/codegen.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1444,8 +1444,10 @@ void jl_generate_fptr(jl_code_instance_t *output)
14441444
break;
14451445
ucache = ucache->next;
14461446
}
1447-
if (codeinst->invoke)
1447+
if (codeinst->invoke) {
1448+
JL_UNLOCK(&codegen_lock);
14481449
return;
1450+
}
14491451
if (ucache != NULL) {
14501452
codeinst->specptr = ucache->specptr;
14511453
codeinst->rettype_const = ucache->rettype_const;

src/gf.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,7 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t
18331833
{
18341834
jl_code_instance_t *codeinst;
18351835
codeinst = mi->cache;
1836+
JL_GC_PROMISE_ROOTED(codeinst);
18361837
while (codeinst) {
18371838
if (codeinst->min_world <= world && world <= codeinst->max_world && codeinst->invoke != NULL) {
18381839
return codeinst;
@@ -1869,6 +1870,7 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t
18691870
}
18701871
}
18711872

1873+
JL_LOCK(&codegen_lock);
18721874
codeinst = mi->cache;
18731875
while (codeinst) {
18741876
if (codeinst->min_world <= world && world <= codeinst->max_world && codeinst->functionObjectsDecls.functionObject != NULL)
@@ -1893,17 +1895,20 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t
18931895
jl_generate_fptr(ucache);
18941896
if (ucache->invoke != jl_fptr_sparam &&
18951897
ucache->invoke != jl_fptr_interpret_call) {
1898+
JL_UNLOCK(&codegen_lock);
18961899
return ucache;
18971900
}
18981901
jl_code_instance_t *codeinst = jl_set_method_inferred(mi, (jl_value_t*)jl_any_type, NULL, NULL,
18991902
0, 1, ~(size_t)0);
19001903
codeinst->specptr = ucache->specptr;
19011904
codeinst->rettype_const = ucache->rettype_const;
19021905
jl_atomic_store_release(&codeinst->invoke, ucache->invoke);
1906+
JL_UNLOCK(&codegen_lock);
19031907
return codeinst;
19041908
}
19051909
}
19061910

1911+
JL_UNLOCK(&codegen_lock);
19071912
jl_generate_fptr(codeinst);
19081913
return codeinst;
19091914
}

0 commit comments

Comments
 (0)