Skip to content

Commit

Permalink
Add GC-safe region around Highs_run
Browse files Browse the repository at this point in the history
Prevent a long-running `Highs_run` call from blocking GC (and
freezing the other Julia threads).
  • Loading branch information
kpamnany committed Oct 4, 2023
1 parent 7316ac9 commit e632c5f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/gen/libhighs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,19 @@ Optimize a model. The algorithm used by HiGHS depends on the options that have b
A `kHighsStatus` constant indicating whether the call succeeded.
"""
function Highs_run(highs)
ccall((:Highs_run, libhighs), HighsInt, (Ptr{Cvoid},), highs)
r = 0
# if `Highs_run` implicitly uses memory or other resources owned by `highs`, preserve it
GC.@preserve highs begin
# allow Julia to GC while this thread is in `Highs_run`
gc_state = ccall(:jl_gc_safe_enter, Int8, ())

r = ccall((:Highs_run, libhighs), HighsInt, (Ptr{Cvoid},), highs)

# leave GC-safe region, waiting for GC to complete if it's running
ccall(:jl_gc_safe_leave, Cvoid, (Int8,), gc_state)
end

return r
end

"""
Expand Down

0 comments on commit e632c5f

Please sign in to comment.