Skip to content

Variable in synchronized hashtable seems not thread-safe #13

@MeCRO-DEV

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?

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