CPU affinity fixes

Hi,

Here are two patches for the CPU affinity setting feature.
Code review and testing are appreciated.

Regards,