diff --git a/src/gen/libhighs.jl b/src/gen/libhighs.jl index 536579f..d8757b8 100644 --- a/src/gen/libhighs.jl +++ b/src/gen/libhighs.jl @@ -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 """