Skip to content

Commit 0849742

Browse files
authored
add GC.safepoint() for compute-bound threads (#33092)
1 parent 5a496c0 commit 0849742

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

base/gcutils.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,19 @@ macro preserve(args...)
9494
end)
9595
end
9696

97+
"""
98+
GC.safepoint()
99+
100+
Inserts a point in the program where garbage collection may run.
101+
This can be useful in rare cases in multi-threaded programs where some threads
102+
are allocating memory (and hence may need to run GC) but other threads are doing
103+
only simple operations (no allocation, task switches, or I/O).
104+
Calling this function periodically in non-allocating threads allows garbage
105+
collection to run.
106+
107+
!!! compat "Julia 1.4"
108+
This function is available as of Julia 1.4.
109+
"""
110+
safepoint() = ccall(:jl_gc_safepoint, Cvoid, ())
111+
97112
end # module GC

doc/src/base/base.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ Base.functionloc(::Method)
395395
Base.GC.gc
396396
Base.GC.enable
397397
Base.GC.@preserve
398+
Base.GC.safepoint
398399
Meta.lower
399400
Meta.@lower
400401
Meta.parse(::AbstractString, ::Int)

0 commit comments

Comments
 (0)