fix lockutils.lock() to make it thread-safe

lockutils.lock() is currenctly safe when used with greenthreads, but it is not
safe when used with classic threads. This change uses a lock to protect
_semaphores dictionary.

Change-Id: Ia18e6e9f9a1353640729ac57d7225c660159cd55
Closes-Bug: 1065529
Merge "fix lockutils.lock() to make it thread-safe"