This patch fixes cases where some state in multithreaded tasks was not properly
being cleaned up.

Most typically an application coredump
