Ensure all threads are either joined or detached

Prevents memory from leaking when threads are rapidly created and cancelled