Starting the message-dispatching execution thread

auto clinstance = myClass::create();

x::start_threadmsgdispatcher(clinstance);

Note

In Makefile.am:

AM_CXXFLAGS=@STDTHREAD_CXXFLAGS@

x::run() and x::start_threadmsgdispatcher() requires additional compilation flags for threading support added to the Makefile.am, from the @STDTHREAD_CXXFLAGS@ which gets set up from configure.ac.

x::start_threadmsgdispatcher must be used to start an execution thread for a subclass of x::threadmsgdispatcherObj. x::start_threadmsgdispatcher() is a wrapper for x::run(). The first parameter to the execution thread's run() message is a reference to an opaque mcguffin. Any remaining parameters to x::start_threadmsgdispatcher() get forwarded as additional parameters to the thread's run() method:

    void run(x::ptr<x::obj> &threadmsgdispatcher_mcguffin)
    {
        msgqueue_auto msgqueue(this);

        threadmsgdispatcher_mcguffin=nullptr;

        try {
            while (1)
                msgqueue.event();

        } catch (const x::stopexception &)
        {
        } catch (const x::exception &e)
        {
            LOG_ERROR(e);
            LOG_TRACE(e->backtrace);
        }
    }

The execution thread's run() method takes the following actions:

x::start_threadmsgdispatcher() does not return until the new execution thread destroys the mcguffin. This is why the mcguffin parameter gets passed to run() by reference, rather than value. This ensures that the new threads message queue exists after x::start_threadmsgdispatcher() returns.