improve pthread implementation