Fixed pthreads implementation