rust-lang / rust-lang/rust

Can we avoid the heap allocation in macOS Mutex/Condvar?

Open
#131,005 2 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-atomic C-optimization O-macos T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

This was brought up over here: our current macOS implementation for Mutex and Condvar use heap allocations. That's unfortunate because it can lead to OOM, and also seems like a slight efficiency hit.

Heap allocations are required because we are using the pthread API on macOS, and pthread Mutexes are not movable. AFAIK, @joboet has been working on alternative implementations that avoid the pthread API (https://github.com/rust-lang/rust/pull/122408). The alternative, suggested by @daira , is to get Apple to guarantee that their pthread mutexes are movable under certain conditions. Given the black box that Apple is, I have no idea if that's even remotely realistic. But anyway it seems worth tracking this somewhere so here we go. :)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the linked discussion in issue #93740 and the alternative implementation in pull request #122408. The work is complete when the macOS Mutex and Condvar implementation avoids heap allocation without changing their required behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
operating-systems
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.