Skip to content

Commit c08ca53

Browse files
authored
Add GC-safe region around Highs_run (#178)
Prevent a long-running `Highs_run` call from blocking GC (and freezing the other Julia threads).
1 parent 7316ac9 commit c08ca53

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/MOI_wrapper.jl

+8-1
Original file line numberDiff line numberDiff line change
@@ -1812,7 +1812,14 @@ function MOI.optimize!(model::Optimizer)
18121812
_set_variable_primal_start(model)
18131813
ret = Highs_zeroAllClocks(model)
18141814
_check_ret(ret)
1815-
ret = Highs_run(model)
1815+
# if `Highs_run` implicitly uses memory or other resources owned by `model`, preserve it
1816+
GC.@preserve model begin
1817+
# allow Julia to GC while this thread is in `Highs_run`
1818+
gc_state = ccall(:jl_gc_safe_enter, Int8, ())
1819+
ret = Highs_run(model)
1820+
# leave GC-safe region, waiting for GC to complete if it's running
1821+
ccall(:jl_gc_safe_leave, Cvoid, (Int8,), gc_state)
1822+
end
18161823
_store_solution(model, ret)
18171824
# TODO(odow): resetting the bounds here invalidates previously stored
18181825
# solutions.

0 commit comments

Comments
 (0)