I have a memory heap manager which partitions the heap into different segments based on the number of processors on the system. Memory can only be allocated on the partitio
From output of man sched_getcpu:
NAME
sched_getcpu - determine CPU on which the calling thread is running
SYNOPSIS
#define _GNU_SOURCE
#include
int sched_getcpu(void);
DESCRIPTION
sched_getcpu() returns the number of the CPU
on which the calling thread is currently executing.
RETURN VALUE
On success, sched_getcpu() returns a non-negative CPU number.
On error, -1 is returned and errno is set to indicate the error.
SEE ALSO
getcpu(2)
Unfortunately, this is Linux specific. I doubt there is a portable way to do this.