Skip to content

Variable in synchronized hashtable seems not thread-safe #13

Description

@MeCRO-DEV

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions