Count the number of threads during tests to find leaks. See #2936