Do not cleanup global allocations if threads are still active.
Merge pull request #1844 from jimis/master

Do not cleanup global allocations if threads are still active.