PSParallel icon indicating copy to clipboard operation
PSParallel copied to clipboard

Variable in synchronized hashtable seems not thread-safe

Open MeCRO-DEV opened this issue 4 years ago • 0 comments

I have a variable: $syncHash.count, which is supposed to be thread-safe. But in this case, it's not: $collection | Invoke-Parallel -scriptblock { $syncHash.count ++ } I have to use mutex to protect it, in order to get correct count: $collection | Invoke-Parallel -scriptblock { $syncHash.mutex.WaitOne() $syncHash.count ++ $syncHash.mutex.ReleaseMutex() }

Is this normal?

MeCRO-DEV avatar Apr 19 '21 04:04 MeCRO-DEV