'Ends a critical section started with self.StartWork().'

def FinishWork(self, instruction=None):

    if ((not instruction) or (instruction == ThreadGate.HOLD)):
        self.__thread_semaphore.release()
    elif (instruction == ThreadGate.INCREASE):
        if (self.__backoff_time > 0.0):
            logger.info('Resetting    backoff    to    0.0')
            self.__backoff_time = 0.0
        do_enable = False
        self.__lock.acquire()
        try:
            if (self.__num_threads > self.__enabled_count):
                do_enable = True
                self.__enabled_count += 1
        finally:
            self.__lock.release()
        if do_enable:
            logger.debug('Increasing    active    thread    count    to    %d', self.__enabled_count)
            self.__thread_semaphore.release()
        self.__thread_semaphore.release()
    elif (instruction == ThreadGate.DECREASE):
        do_disable = False
        self.__lock.acquire()
        try:
            if (self.__enabled_count > 1):
                do_disable = True
                self.__enabled_count -= 1
            elif (self.__backoff_time == 0.0):
                self.__backoff_time = INITIAL_BACKOFF
            else:
                self.__backoff_time *= BACKOFF_FACTOR
        finally:
            self.__lock.release()
            if do_disable:
                logger.debug('Decreasing    the    number    of    active    threads    to    %d', self.__enabled_count)
            else:
                self.__thread_semaphore.release()
