pthreads: fixed some segfaults