def compare_and_set(self, expect, update):
        '''
        Atomically sets the value to `update` if the current value is equal to
        `expect`.

        :param expect: The expected current value.
        :param update: The value to set if and only if `expect` equals the
            current value.
        '''
        with self._lock.exclusive:
            if self._value == expect:
                self._value = update
                return True

            return False