Implement MasterElection

Could take a ```const unique_lock<mutex>&``` and ```CHECK(lock.owns_lock())``` (everywhere that calls this has one).