Implement atomic counters

This pull request implements *dynamic semaphores* mentioned in issues #36.