changed to posix threads (crossplatform)