jc_utils: maintain the number of running tasks.

This value will be used in determining whether we can run tasks of a stage or
not.
jc_utils: Limit the degree of concurrency of the stages.
Merge pull request #527 from pooya/avoid_deadlock

Avoid deadlock