cleanup thread context