-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
std: use sync::Mutex
for internal statics
#100579
Conversation
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
r? @m-ou-se (rust-highfive has picked a reviewer for you, use r? to override) |
c624583
to
6ffd8e4
Compare
LGTM |
The hermit changes look good to me. 👍 |
Looks also good for me! |
6ffd8e4
to
dce2d6a
Compare
As mentioned in #100581 I'm not a fan of this. I care more about this on Darwin than on other platforms, and a bit more about this for StaticMutex than StaticRwlock. I also would eventually like to move StaticMutex on Darwin to |
I agree that that'd be good. If we decouple the mutex and condition variable on macOS, we could possibly also make the standard |
I guess it wouldn't be the end of the world. It looks like on Darwin the only time we actually would be taking a StaticMutex is when producing a backtrace and spawning processes (it has 64 bit atomics, and doesnt require synchronized create for TLS). These aren't so performance sensitive that an additional allocation will matter. |
r? @thomcc |
This looks fine. This takes locks in the same cases as before (well, strictly fewer, actually -- hermit will use atomics with this PR), so there should be no concerns about additional deadlocks here (mentioned by @m-ou-se on Zulip). No rollup for similar reasons to the rwlock changes. @bors r+ rollup=never |
📌 Commit dce2d6a65d5bf154003eb95f1cc152b46097921c has been approved by It is now in the queue for this repository. |
That would be great, but it probably requires Apple to promise that the |
os_unfair_lock doesn't have constructor nor a destructor function, which is nearly enough to guarantee it's movable: moving a freshly initialized os_unfair_lock is equivalent to just destructing it in place and creating a new one in a new location. I guess the only thing that's technically missing is the guarantee that this still works after locking and unlocking. But without a destructor, it's safe to assume there's no external pointers pointing into it. And with its tiny size (1 pointer), internal pointers or alignment-dependent operation also seem very unlikely. (But yes, official confirmation from Apple would be nice. ^^) |
⌛ Testing commit dce2d6a65d5bf154003eb95f1cc152b46097921c with merge fc4d094db22a53d020f3486c334dd9bee77b503a... |
It's hard to get Apple to update their documentation, so I wouldn't hold my breath there honestly. If we want to block using it on that, I could file an issue with them to ask though (I have a dev account and don't mind). That said, I agree it's unclear on whether or not it's worth using for Mutex, given the trickiness it adds to condvars (it's hard for me to imagine we'd have an impl that doesn't penalize condvar-heavy code, for example). I agree that it's hard to imagine this being immovable in any way, especially given that it's intended as a replacement for OSSpinLock. |
If the condvar implementation is changed to a parking-lot or atomic queue (see |
⌛ Testing commit 2d2c9e4 with merge 3993d24c2658c1b2e4a9e0600bf6cbec13a246f1... |
💥 Test timed out |
…omcc std: use `sync::Mutex` for internal statics Since `sync::Mutex` is now `const`-constructible, it can be used for internal statics, removing the need for `sys_common::StaticMutex`. This adds some extra allocations on platforms which need to box their mutexes (currently SGX and some UNIX), but these will become unnecessary with the lock improvements tracked in rust-lang#93740. I changed the program argument implementation on Hermit, it does not need `Mutex` but can use atomics like some UNIX systems (ping `@mkroening` `@stlankes).`
This seems like a spurious failure, as the tests passed before and nothing was changed for macOS since. |
@bors delegate+ |
✌️ @joboet can now approve this pull request |
@bors r+ rollup=iffy |
💡 This pull request was already approved, no need to approve it again.
|
@bors r- r=thomcc |
☀️ Test successful - checks-actions |
Finished benchmarking commit (ddc7fd9): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Footnotes |
Since
sync::Mutex
is nowconst
-constructible, it can be used for internal statics, removing the need forsys_common::StaticMutex
. This adds some extra allocations on platforms which need to box their mutexes (currently SGX and some UNIX), but these will become unnecessary with the lock improvements tracked in #93740.I changed the program argument implementation on Hermit, it does not need
Mutex
but can use atomics like some UNIX systems (ping @mkroening @stlankes).