Update the cpu core count detection functions for linux and mac os

This fixes building of the thread library code on linux (where it failed due to ignoring return values from functions). Avoiding a fork()/system() call is an another additional benefit.

On OS X, don't use a deprecated system function for detecting the number of cores.