threads.h implementation