Critical section for each task

Fixes #6