locking: support shared memory locking

Squashed merge of Otto's pull request #151.