std::thread support for the Nintendo 3DS by AzureMarker · Pull Request #98514 · rust-lang/rust (original) (raw)

Rustc supports compiling for the Nintendo 3DS using the armv6k-nintendo-3ds target (Tier 3). Just recently we merged std support in #95897. A notable exclusion was std::thread support, which was moved into this PR as a follow-up since it required more complicated changes.

See #95897 for background on how rustc is able to support std for the 3DS.

A notable change in this PR is the addition of a "native options" parameter to the internal implementation of the thread builder on each platform. This is due to the 3DS requiring the "processor ID" where the thread should be spawned (certain cores are either cooperative or preemptive) and the thread priority up-front. There is an unstable thread builder extension trait added which allows users to set these values.

There are 2 non-portable pthread APIs which we depend on. Where possible, we tried to reuse existing standard APIs, but there are some features of the 3DS thread system which required us to add non-portable functions.

  1. pthread_attr_setprocessorid_np: Used to set the new thread's processor ID.
  2. pthread_getprocessorid_np: Used to retrieve the current thread's processor ID.

These are both implemented by https://github.com/Meziu/pthread-3ds, which is already noted as in the platform support doc as a requirement for the target's std support (note: it provides the backend for other pthread-based types such as Mutex). These functions have already been added to libc and are in the currently used version (rust-lang/libc#2715).

Edit: libs team ACP has been opened for the changes to the thread builder: rust-lang/libs-team#71

Blocked on #101222 and ACP rust-lang/libs-team#71 rust-lang/libs-team#195