Fix bad casts in thread intrinsics that broke some platforms