changed to posix threads for crossplatform