Add thread affinity code for Mac OS X.
Solve type mismatch on 64-bit Darwin and gcc 4.9.