Skip to content

Commit

Permalink
Add GC-safe region around Highs_run (#178)
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 authored Oct 5, 2023
1 parent 7316ac9 commit c08ca53
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1812,7 +1812,14 @@ function MOI.optimize!(model::Optimizer)
_set_variable_primal_start(model)
ret = Highs_zeroAllClocks(model)
_check_ret(ret)
ret = Highs_run(model)
# if `Highs_run` implicitly uses memory or other resources owned by `model`, preserve it
GC.@preserve model begin
# allow Julia to GC while this thread is in `Highs_run`
gc_state = ccall(:jl_gc_safe_enter, Int8, ())
ret = Highs_run(model)
# leave GC-safe region, waiting for GC to complete if it's running
ccall(:jl_gc_safe_leave, Cvoid, (Int8,), gc_state)
end
_store_solution(model, ret)
# TODO(odow): resetting the bounds here invalidates previously stored
# solutions.
Expand Down

0 comments on commit c08ca53

Please sign in to comment.