Fix a crash in how we monitor thread activity. Use pthread cleanup functionality instead of pthread_t, which is no longer valid after a thread has exited. TRQ-1745.