Add additional debug code to try and track down a rare segfault in threading.