Implement MasterElection

Taking the lock here **shouldn't** be necessary, as you should always have synchronized your last usage of an object with its destruction, of course... :wink: 

Was that brought out by a TSAN warning or something like that? Or just being paranoid?