Portable multithreading primitives