Add cycle detecting locks, fix Orchid deadlock 2

https://github.com/subgraph/Orchid/pull/10