LBFGS/LBFGSB optimizerv4 crash in Multi-threaded application

This optimizer is not threading safe, so when I run two(or more) threads simultaneously containing this optimizer, the results are irreproducible, and may even crash at different breakpoints.

When I switch to other kind of optimizers , the results are reproducible, no crashes.

I doubt some static variables causing these problems, but I have not found them yet**.**

LGFGSB is the only one with bounds, so I’m not free to switch to other optimizers

Can I get any help or suggustions?

I would give Thread Sanitizer a try.

edit correction: Two(or more) threads simultaneously, each containing one LBFGSB optimizer instances

Tested on itk5.4 and latest itk6.0