Skip to content

Commit

Permalink
Expand on docstring of GC.safepoint (#57128)
Browse files Browse the repository at this point in the history
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'
  • Loading branch information
jakobnissen authored Jan 23, 2025
1 parent 090e291 commit f52c4ab
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions base/gcutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,21 @@ end
GC.safepoint()
Inserts a point in the program where garbage collection may run.
This can be useful in rare cases in multi-threaded programs where some threads
are allocating memory (and hence may need to run GC) but other threads are doing
only simple operations (no allocation, task switches, or I/O).
Calling this function periodically in non-allocating threads allows garbage
Safepoints are fast and do not themselves trigger garbage collection.
However, if another thread has requested the GC to run, reaching a safepoint will
cause the current thread to block and wait for the GC.
This can be useful in rare cases in multi-threaded programs where some tasks
are allocating memory (and hence may need to run GC) but other tasks are doing
only simple operations (no allocation, task switches, or I/O), which do not
yield control to Julia's runtime, and therefore blocks the GC from running.
Calling this function periodically in the non-allocating tasks allows garbage
collection to run.
Note that even though safepoints are fast (typically around 2 clock cycles),
they can still degrade performance if called in a tight loop.
!!! compat "Julia 1.4"
This function is available as of Julia 1.4.
"""
Expand Down

0 comments on commit f52c4ab

Please sign in to comment.