Skip to content

Commit a873a90

Browse files
committed
Workaround possible GC dead loop
This is necessary before the gc safepoint/transition support in codegen.
1 parent 5e01b1a commit a873a90

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

base/atomics.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ for op in [:+, :-, :max, :min]
186186
cmp = old
187187
old = atomic_cas!(var, cmp, new)
188188
reinterpret(IT, old) == reinterpret(IT, cmp) && return new
189+
# Temporary solution before we have gc transition support in codegen.
190+
# This could mess up gc state when we add codegen support.
191+
# Use these as a safe point
192+
gc_state = ccall(:jl_gc_safe_enter, Int8, ())
193+
ccall(:jl_gc_safe_leave, Void, (Int8,), gc_state)
189194
end
190195
end
191196
end

test/threads.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ function test_atomic_read(commbuf::CommBuf, n::Int)
166166
var1 = commbuf.var1[]
167167
correct &= var1 >= var2
168168
var1 == n && break
169+
# Temporary solution before we have gc transition support in codegen.
170+
# This could mess up gc state when we add codegen support.
171+
# Use these as a safe point
172+
gc_state = ccall(:jl_gc_safe_enter, Int8, ())
173+
ccall(:jl_gc_safe_leave, Void, (Int8,), gc_state)
169174
end
170175
commbuf.correct_read = correct
171176
end
@@ -208,6 +213,11 @@ function test_fence(p::Peterson, id::Int, n::Int)
208213
p.turn[] = otherid
209214
atomic_fence()
210215
while p.flag[otherid][] != 0 && p.turn[] == otherid
216+
# Temporary solution before we have gc transition support in codegen.
217+
# This could mess up gc state when we add codegen support.
218+
# Use these as a safe point
219+
gc_state = ccall(:jl_gc_safe_enter, Int8, ())
220+
ccall(:jl_gc_safe_leave, Void, (Int8,), gc_state)
211221
# busy wait
212222
end
213223
# critical section
@@ -260,6 +270,11 @@ function test_atomic_cas!{T}(var::Atomic{T}, range::StepRange{Int,Int})
260270
while true
261271
old = atomic_cas!(var, T(i-1), T(i))
262272
old == T(i-1) && break
273+
# Temporary solution before we have gc transition support in codegen.
274+
# This could mess up gc state when we add codegen support.
275+
# Use these as a safe point
276+
gc_state = ccall(:jl_gc_safe_enter, Int8, ())
277+
ccall(:jl_gc_safe_leave, Void, (Int8,), gc_state)
263278
end
264279
end
265280
end

0 commit comments

Comments
 (0)