Make TaskManager safe for concurrent access

Issue #9