Defer destruction of threads which tries to self-destruct. Check an perform cleanup of such threads during pthread_cancel and pthread_create. Issue #1687