title: How do I find the cpu the current thread is running on, for Mac and BSD?
body: <p>I'm looking for a function on Mac OS and BSD that's equivalent to Linux's <code>sched_getcpu()</code>, and Windows' <code>GetCurrentProcessorNumberEx()</code> in order to implement a library for cpu-local storage. It's clearly possible to emulate this with the cpuid or rdtscp instructions, but it's possible to do better with kernel cooperation: <a href="https://lkml.org/lkml/2007/1/6/190" rel="nofollow">https://lkml.org/lkml/2007/1/6/190</a>.</p>
  
  <p>I already know that the thread's current CPU may change by the time I use the information.</p>