# LBFGS/LBFGSB optimizerv4 crash in Multi-threaded application

**URL:** https://discourse.itk.org/t/lbfgs-lbfgsb-optimizerv4-crash-in-multi-threaded-application/7695
**Category:** Algorithms
**Created:** [January 8, 2026, 1:54am UTC](https://discourse.itk.org/t/lbfgs-lbfgsb-optimizerv4-crash-in-multi-threaded-application/7695 "2026-01-08T01:54:35Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Liming\_Zhou](https://discourse.itk.org/user_avatar/discourse.itk.org/liming_zhou/32/4627_2.png) [@Liming\_Zhou](https://discourse.itk.org/u/Liming_Zhou)
#### Post date: [January 8, 2026, 1:54am UTC](https://discourse.itk.org/t/lbfgs-lbfgsb-optimizerv4-crash-in-multi-threaded-application/7695/1 "2026-01-08T01:54:35Z")

</div>

This optimizer is not threading safe, so when I run two(or more) threads simultaneously containing this optimizer, the results are **[irreproducible](https://www.baidu.com/link?url=r4pqywCHaOKclHW83npMnrcsJ_EHXLLliMVtIgYZGFDvyDdtJlCzUQKQE84FzdsVv50u3LIJTKKtq3lw4SScpK&wd=&eqid=9b570a6901ec056d00000006695f0c2e), and may even crash at different breakpoints.**

When I switch to other kind of optimizers , the results are **[reproducible](https://www.baidu.com/link?url=r4pqywCHaOKclHW83npMnrcsJ_EHXLLliMVtIgYZGFDvyDdtJlCzUQKQE84FzdsVv50u3LIJTKKtq3lw4SScpK&wd=&eqid=9b570a6901ec056d00000006695f0c2e), 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?

---

<div class="post-metadata">

### Author: ![seanm](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/a88e4f/32.png) [@seanm](https://discourse.itk.org/u/seanm)
#### Post date: [January 8, 2026, 9:29pm UTC](https://discourse.itk.org/t/lbfgs-lbfgsb-optimizerv4-crash-in-multi-threaded-application/7695/2 "2026-01-08T21:29:01Z")

</div>

I would give Thread Sanitizer a try.

---

<div class="post-metadata">

### Author: ![Liming\_Zhou](https://discourse.itk.org/user_avatar/discourse.itk.org/liming_zhou/32/4627_2.png) [@Liming\_Zhou](https://discourse.itk.org/u/Liming_Zhou)
#### Post date: [January 9, 2026, 2:19am UTC](https://discourse.itk.org/t/lbfgs-lbfgsb-optimizerv4-crash-in-multi-threaded-application/7695/3 "2026-01-09T02:19:10Z")

</div>

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

Tested on itk5.4 and latest itk6.0
