coin-or / Clp

COIN-OR Linear Programming Solver

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OsiClpSolverInterface::modelCut() is not threadsafe

tosttost opened this issue · comments

In line 3262

static int debugMode = 0;

this global variable is then modified in line 3443. It is unclear to me when/whether this line is executed. If it is and another thread B is running modelCut it is definitely possible that debugModel was not initialized in line 3296, thread A sets debugMode to a value != 0 and thread B calls functions with an uninitialized this pointer (e.g. line 3454) causing undefined behaviour or a segmentation fault.

OsiClpSolverInterface::modelCut is used by Cbc.

this is only used for debugging

I do not claim anything else. But I'm pretty sure the current implementation is not thread safe no matter if you are debugging or not.

debugMode = 0 does skip all the 'if' that modify 'debugModel'. Nevertheless debugMode is modified if modelPtr_->numberColumns_ < 0 no matter what value it had before or if we are running a debug or a release build. After that happend, the 'if' are no longer skipped.

So unless

  • modelCut() is only called in debug builds - seems unlikely to me
  • or 'modelPtr_->numberColumns_ < 0' never happens in release builds

the current implementation is not thread safe in release builds, although the bug will be quite difficult to trigger.

Sounds like a reasonable fix.

Just to follow up, I don't think this ever happened, right?

Oops, sorry, looks like it was done in refactor (5b6a9a6), which is the right place for it. I'm going to close this for now, feel free to reopen if needed.