Skip to main content

Module affinity

Module affinity 

Source
Expand description

Thread CPU-affinity helpers.

set_affinity pins the calling thread to the given set of logical CPU cores. Implementations:

  • Linux: sched_setaffinity(0, ...) via libc syscall.
  • Windows: SetThreadAffinityMask(GetCurrentThread(), mask). Mask is a 64-bit bitfield; cores >= 64 are rejected with AffinityError::Unsupported.
  • *Other (macOS, FreeBSD, BSDs without sched_setaffinity): documented no-op returning AffinityError::Unsupported. macOS exposes only thread-policy affinity hints; we don’t pretend they’re equivalent.

The call only affects the current thread. Spawn-then-pin pattern:

use subms_mpsc_queue::set_affinity;
std::thread::spawn(|| {
    let _ = set_affinity(&[2]);
    // ... hot loop pinned to core 2 ...
});

Enums§

AffinityError
Failure mode for set_affinity.

Functions§

set_affinity
Pin the calling thread to the given set of logical cores.