Skip to content

ReadWriteLock upgradeToWrite fix for simultaneous upgrades.#134

Merged
accelerated merged 1 commit intobloomberg:masterfrom
accelerated:rwmutex-trylock
Nov 8, 2020
Merged

ReadWriteLock upgradeToWrite fix for simultaneous upgrades.#134
accelerated merged 1 commit intobloomberg:masterfrom
accelerated:rwmutex-trylock

Conversation

@accelerated
Copy link
Copy Markdown
Contributor

Description

If ReadWriteLock::upgradeToWrite() was called and there were more than one simultaneous upgrades occurring, the function would block indefinitely. This was caused by the underlying loop calling tryUpgradeToLock() not keeping upgrade state during iterations.
This fix introduces a new overload ReadWriteSpinlock::tryUpgradeToWrite(bool& pendingUpgrade) which should be used if calling this in a loop.

Testing performed
The previous tests only covered calling ReadWriteSpinlock::upgradeToWrite() which worked properly because it was not invoked inside a loop. The ReadWriteMutex::upgradeToWrite() calls it in a loop which was never actually tested. As a validation, running the new added test on the previous master branch blocks indefinitely which proves the fix is working correctly.

Signed-off-by: Alexander Damian adamian@bloomberg.net

Signed-off-by: Alexander Damian <adamian@bloomberg.net>
Copy link
Copy Markdown
Contributor

@arosenzweig3 arosenzweig3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@accelerated accelerated merged commit eff98e7 into bloomberg:master Nov 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants