Fix SelfContainedMutex deadlock and add loom support#2558
Fix SelfContainedMutex deadlock and add loom support#2558sporksmith merged 4 commits intoshadow:mainfrom
Conversation
Codecov ReportBase: 67.43% // Head: 67.79% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #2558 +/- ##
==========================================
+ Coverage 67.43% 67.79% +0.35%
==========================================
Files 193 194 +1
Lines 28651 28784 +133
Branches 5631 5638 +7
==========================================
+ Hits 19320 19513 +193
+ Misses 4875 4787 -88
- Partials 4456 4484 +28
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
|
benchmark run shows no change, as expected https://github.com/shadow/benchmark-results/tree/master/tor/2022-11-21-T17-07-28 |
Loom requires/recommends structuring tests this way, presumably so that when running loom tests you can easily run only these tests with the cargo `--test` flag.
At this point, we get a cascading error under loom, telling us that something is wrong but is a bit tricky to debug. Tests still pass outside of loom.
Use an atomic fence, with AcqRel ordering. This does *not* fix the tests under loom, indicating there is still a problem. See shadow#2557
Fixes shadow#2557 This collapses the lock state and the number of sleepers into a single atomic, which we also use as the futex word. This makes the concurrency correctness much easier to reason about, at the cost of having to do some bit fiddling, and under contention sometimes having to do some extra atomic operations to synchronize the sleeper-count.
Rewrite SelfContainedMutex to fix deadlock and test under loom
Fixes #2557
This collapses the lock state and the number of sleepers into a single atomic, which we also use as the futex word. This makes the concurrency correctness much easier to reason about, at the cost of having to do some bit fiddling, and under contention sometimes having to do some extra atomic operations to synchronize the sleeper-count.
This also adds support for testing SelfContainedMutex using loom. This requires compiling the code specially, and isn't done by default. It can be run under loom with: