More work on locks

Also fixed a spurious failing test with the Topic.
Merge pull request #1872 from pveentjer/morelockwork

More work on locks