Fix compilation and thread stack size issues found on OS X