fn gather_all_x2apic_ids() -> Vec<u32> {
    let core_ids = core_affinity::get_core_ids().unwrap();

    // Create a thread for each active CPU core.
    core_ids
        .into_iter()
        .map(|id| {
            thread::spawn(move || {
                // Pin this thread to a single CPU core.
                core_affinity::set_for_current(id);
                // Do more work after this.
                let cpuid = CpuId::new();
                cpuid.get_extended_topology_info().map_or_else(
                    || 0,
                    |mut topiter| topiter.next().as_ref().unwrap().x2apic_id(),
                )
            })
            .join()
            .unwrap_or(0)
        })
        .collect::<Vec<_>>()
}
/// Runs CPU ID on every core in the system (to gather all x2APIC IDs).
///
/// # Note
/// This won't work on macOS, apparently there is no guarantee after setting the affinity
/// that a thread will really execute on the pinned core.
Runs CPU ID on every core in the system (to gather all x2APIC IDs).
Runs CPU ID on every core in the system ( to gather all x2APIC IDs ) .
fn gather_all_x2apic_ids() -> Vec<u32> {
    let core_ids = core_affinity::get_core_ids().unwrap();
    // Create a thread for each active CPU core.
    core_ids
        .into_iter()
        .map(|id| {
            thread::spawn(move || {
                // Pin this thread to a single CPU core.
                core_affinity::set_for_current(id);
                // Do more work after this.
                let cpuid = CpuId::new();
                cpuid.get_extended_topology_info().map_or_else(
                    || 0,
                    |mut topiter| topiter.next().as_ref().unwrap().x2apic_id(),
                )
            })
            .join()
            .unwrap_or(0)
        })
        .collect::<Vec<_>>()
}
fn gather_all_x2apic_ids ( ) -> Vec < u32 > { let core_ids = core_affinity :: get_core_ids ( ) . unwrap ( ) ; // Create a thread for each active CPU core. core_ids . into_iter ( ) . map ( | id | { thread :: spawn ( move | | { // Pin this thread to a single CPU core. core_affinity :: set_for_current ( id ) ; // Do more work after this. let cpuid = CpuId :: new ( ) ; cpuid . get_extended_topology_info ( ) . map_or_else ( | | 0 , | mut topiter | topiter . next ( ) . as_ref ( ) . unwrap ( ) . x2apic_id ( ) , ) } ) . join ( ) . unwrap_or ( 0 ) } ) . collect :: < Vec < _ > > ( ) }
Runs CPU ID on every core in the system (to gather all x2APIC IDs).
Runs CPU ID on every core in the system ( to gather all x2APIC IDs ) .
note
This won't work on macOS, apparently there is no guarantee after setting the affinity
that a thread will really execute on the pinned core.
This won ' t work on macOS apparently there is no guarantee after setting the affinity that a thread will really execute on the pinned core .