physics: use pthread_cancel to stop threads

Nothing is getting stuck now, every thread quits when asked to. Previously the problem was a thread might have locked a mutex or on a barrier while another thread quit, so it got stuck. Now the delay between the loop to cancel threads and the loop to join up with them is sufficient so that nothing will get stuck.