Make re-compile thread-safe

Under heavy load, we sometimes see the following error (see issue #214)
Exception in thread Thread-328:
  File "/pkg/lib/python2.7/site-packages/web/utils.py", line 500, in __call__
    update(block=True)
  File "/pkg/lib/python2.7/site-packages/web/utils.py", line 497, in update
    self.running[key].release()
error: release unlocked lock

This can happen when there is a thread-switch between the test and creation
of self.running[key]. In this patch we acquire a lock first
to make the test+create atomic.