PSParallel
PSParallel copied to clipboard
Variable in synchronized hashtable seems not thread-safe
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?