Add facilities for cleanly terminating threads