[rt] Detach thread when destroying it

This changes comes from HARP.