threadId in ParallelizeImageRegion

There are two components to be aware of:

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.

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 line 62 to really the only line that does it.