Threads: Fix bug in TaskCountManager.get_tasks().

Mutex was not released at exit.