Skip to content

Commit f52c4ab

Browse files
authored
Expand on docstring of GC.safepoint (JuliaLang#57128)
Update the docstring to mention the following points: * Safepoints are very fast, but may still degrade performance in tight loops * Safepoints do not trigger the GC, but instead stops a task from blocking GC that would otherwise run. * Switch terminology from mentioning 'threads' to 'tasks'
1 parent 090e291 commit f52c4ab

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

base/gcutils.jl

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,21 @@ end
243243
GC.safepoint()
244244
245245
Inserts a point in the program where garbage collection may run.
246-
This can be useful in rare cases in multi-threaded programs where some threads
247-
are allocating memory (and hence may need to run GC) but other threads are doing
248-
only simple operations (no allocation, task switches, or I/O).
249-
Calling this function periodically in non-allocating threads allows garbage
246+
247+
Safepoints are fast and do not themselves trigger garbage collection.
248+
However, if another thread has requested the GC to run, reaching a safepoint will
249+
cause the current thread to block and wait for the GC.
250+
251+
This can be useful in rare cases in multi-threaded programs where some tasks
252+
are allocating memory (and hence may need to run GC) but other tasks are doing
253+
only simple operations (no allocation, task switches, or I/O), which do not
254+
yield control to Julia's runtime, and therefore blocks the GC from running.
255+
Calling this function periodically in the non-allocating tasks allows garbage
250256
collection to run.
251257
258+
Note that even though safepoints are fast (typically around 2 clock cycles),
259+
they can still degrade performance if called in a tight loop.
260+
252261
!!! compat "Julia 1.4"
253262
This function is available as of Julia 1.4.
254263
"""

0 commit comments

Comments
 (0)