Use a per thread var to singla its cancellation rather than relying on pthread_cancel. do the cleanup there as well