# threadId in ParallelizeImageRegion

**URL:** https://discourse.itk.org/t/threadid-in-parallelizeimageregion/1008
**Category:** Engineering
**Created:** [June 15, 2018, 11:52am UTC](https://discourse.itk.org/t/threadid-in-parallelizeimageregion/1008 "2018-06-15T11:52:34Z")
**Posts on this page:** 1
**Showing post:** 7

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [June 15, 2018, 12:57pm UTC](https://discourse.itk.org/t/threadid-in-parallelizeimageregion/1008/7 "2018-06-15T12:57:34Z")

</div>

There are two components to be aware of:

- [SimpleFastMutexLock](https://itk.org/Doxygen/html/classitk_1_1SimpleFastMutexLock.html)
- [MutexLockHolder](https://itk.org/Doxygen/html/classitk_1_1MutexLockHolder.html)

The mutex is variable scoped to provide serialized access. For your case, the need is to control access to threads in an instance of the class. So you are looking at a lock with object scope, a member variable.

The holder provides exception safe lock/unlock handling of the mutex via [RAII](https://en.cppreference.com/w/cpp/language/raii).

Here is an example which controls initialization and access to a global variable:  
[https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Core/Common/src/itkMersenneTwisterRandomVariateGenerator.cxx#L62-L72](https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Core/Common/src/itkMersenneTwisterRandomVariateGenerator.cxx#L62-L72) line 62 to really the only line that does it.

---

_[View the full topic](https://discourse.itk.org/t/threadid-in-parallelizeimageregion/1008)._
