# A static variable in itkNiftiImageIO.cxx

**URL:** https://discourse.itk.org/t/a-static-variable-in-itkniftiimageio-cxx/7698
**Category:** Engineering
**Tags:** itk
**Created:** [January 12, 2026, 7:41am UTC](https://discourse.itk.org/t/a-static-variable-in-itkniftiimageio-cxx/7698 "2026-01-12T07:41:55Z")
**Posts on this page:** 4
**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 12, 2026, 7:41am UTC](https://discourse.itk.org/t/a-static-variable-in-itkniftiimageio-cxx/7698/1 "2026-01-12T07:41:55Z")

</div>

static std::string prev;  
if (prev != this-\>GetFileName())  
{  
#if defined(ITK\_USE\_VERY\_VERBOSE\_NIFTI\_DEBUGGING)  
DumpNiftiHeader(this-\>GetFileName());  
#endif  
prev = this-\>GetFileName();  
}

this “prev” useless maybe, **damaging** Thread Safety

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [January 12, 2026, 6:00pm UTC](https://discourse.itk.org/t/a-static-variable-in-itkniftiimageio-cxx/7698/2 "2026-01-12T18:00:30Z")

</div>

Is this related to NRRD thread-safety discussion on [GitHub PR](https://github.com/InsightSoftwareConsortium/ITK/pull/5684)?

---

<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: [February 7, 2026, 9:34pm UTC](https://discourse.itk.org/t/a-static-variable-in-itkniftiimageio-cxx/7698/3 "2026-02-07T21:34:12Z")

</div>

> <https://github.com/InsightSoftwareConsortium/ITK/pull/5780>

---

<div class="post-metadata">

### Author: ![hele](https://discourse.itk.org/letter_avatar_proxy/v4/letter/h/a698b9/32.png) [@hele](https://discourse.itk.org/u/hele)
#### Post date: [February 12, 2026, 11:48am UTC](https://discourse.itk.org/t/a-static-variable-in-itkniftiimageio-cxx/7698/4 "2026-02-12T11:48:39Z")

</div>

Yes, itkNiftiImageIO’s `static std::string prev;` is not thread-safe.

Since function-level statics are shared by threads, suppressing DumpNiftiHeader in a multi-threaded ITK pipeline requires the introduction of hidden shared state. Not worth it.

It was the proper decision to remove it. Thread safety \> small debug optimization is the reason ITK IO must be re-entrant.
