CPU_SET( SOME_CORE_INT, &mask);
int error = sched_setaffinity(0, sizeof mask, &mask);
Using this significantly improved the scaling of my multicore tree visitors. I still haven't found a good way to do it on OS X systems, which only seems to support affinity across units with distinct L2 caches.
I believe it's more general than pinning in that it could be used for affinity by setting multiple potential cores. Tuning for hyperthreads is iffy in that I believe the hardware context -> logical cpu mapping is unreliable (e.g., no guarantee the HTs are contiguously named).
Edit: also, all you need to do is link in -lpthread and include "pthread.h" ; no more funny business.