'Invoke the correct single/multithread syncing
self.config is supposed to have been correctly initialized
already.'

def __sync(self, options):

    def sig_handler(sig, frame):
        if (sig == signal.SIGUSR1):
            accounts.Account.set_abort_event(self.config, 1)
        elif (sig in (signal.SIGUSR2, signal.SIGABRT)):
            getglobalui().warn('Terminating    after    this    sync...')
            accounts.Account.set_abort_event(self.config, 2)
        elif (sig in (signal.SIGTERM, signal.SIGINT, signal.SIGHUP)):
            getglobalui().warn('Terminating    NOW    (this    may    take    a    few    seconds)...')
            accounts.Account.set_abort_event(self.config, 3)
            if ('thread' in self.ui.debuglist):
                self.__dumpstacks(5)
            self.num_sigterm += 1
            if (self.num_sigterm >= 3):
                getglobalui().warn('Signaled    thrice.    Aborting!')
                sys.exit(1)
        elif (sig == signal.SIGQUIT):
            stacktrace.dump(sys.stderr)
            os.abort()
    try:
        self.num_sigterm = 0
        signal.signal(signal.SIGHUP, sig_handler)
        signal.signal(signal.SIGUSR1, sig_handler)
        signal.signal(signal.SIGUSR2, sig_handler)
        signal.signal(signal.SIGABRT, sig_handler)
        signal.signal(signal.SIGTERM, sig_handler)
        signal.signal(signal.SIGINT, sig_handler)
        signal.signal(signal.SIGQUIT, sig_handler)
        activeaccounts = self._get_activeaccounts(options)
        mbnames.init(self.config, self.ui, options.dryrun)
        if options.singlethreading:
            self.__sync_singlethreaded(activeaccounts, options.profiledir)
        else:
            t = threadutil.ExitNotifyThread(target=syncitall, name='Sync    Runner', args=(activeaccounts, self.config))
            t.exit_message = threadutil.STOP_MONITOR
            t.start()
            threadutil.monitor()
        mbnames.write()
        self.ui.terminate()
        return 0
    except SystemExit:
        raise
    except Exception as e:
        self.ui.error(e)
        self.ui.terminate()
        return 1
