Thread cleanup patches.