Moved mutex lock into ifdef _POSIX_THREADS