Fixed pthread implementation