Skip to content

Conversation

@joboet
Copy link
Member

@joboet joboet commented Nov 7, 2025

The documentation for Condvar::wait currently states that

This function may panic! if it is used with more than one mutex over time.

This is however only true on UNIX platforms that still use the pthread Condvar implementation (namely macOS, some BSDs like NetBSDs and some very niche platforms like VxWorks), making it likely that users will not be aware of this caveat.

Hence in this PR, I've modified the pthread-based implementation to allow multi-mutex-use by adding an inner mutex that bridges the gap between the unlock operation on the user-specified mutex and the actual condvar wait.

Note that this closes the door on making the futex-based notify_all() a requeuing operation, as the waiters might not be sharing the same mutex. At the same time, the implementation change here makes it easier to switch the Mutex implementation independent of the Condvar one, which would e.g. simplify switching it to employ os_unfair_lock on macOS.

@rustbot label +I-libs-api-nominated

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 7, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 7, 2025

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the I-libs-nominated Nominated for discussion during a libs team meeting. label Nov 7, 2025
@rust-log-analyzer

This comment has been minimized.

@joboet joboet force-pushed the condvar_multiple_mutexes branch from f2071c0 to d46f8ad Compare November 8, 2025 08:00
@rustbot
Copy link
Collaborator

rustbot commented Nov 8, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rustbot rustbot added the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Nov 8, 2025
@joboet joboet removed the I-libs-nominated Nominated for discussion during a libs team meeting. label Nov 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

I-libs-api-nominated Nominated for discussion during a libs-api team meeting. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants