• Multithreaded ACE/TAO traces.

    From Tomek@21:1/5 to All on Tue Oct 13 23:27:15 2015
    Hi All,

    How to configure ACE/TAO traces to have them working in multithreaded application?
    It works fine in single threaded application, but If I want other threads to produce debug information it does not work.

    To show what I mean I modified slightly the ACE_wrappers/examples/APG/Logging/Use_Callback.cpp code
    and added pthread_create to them:


    #include <stdio.h>
    #include <iostream>
    #include <pthread.h>
    #include "ace/Log_Msg.h"
    #include "ace/Log_Msg_Callback.h"
    #include "ace/Log_Record.h"
    using namespace std;
    class Callback : public ACE_Log_Msg_Callback
    {
    public:
    void log (ACE_Log_Record &log_record)
    {
    cout << "CALLBACK " << log_record.msg_data() << flush;
    }
    };

    static void * my_thread(void *arg)
    {
    cout << "my_thread started" << endl << flush;
    while (1)
    {
    ACE_DEBUG ((LM_DEBUG, "(%P|%t) <%N %l> my_thread loop debug\n")); // <- I never see this entry
    cout << "my_thread loop cout" << endl << flush;
    sleep(10);
    }
    }

    int main (int argc, char *argv[] )
    {
    Callback *callback = new Callback;
    ACE_LOG_MSG->set_flags (ACE_Log_Msg::MSG_CALLBACK);
    ACE_LOG_MSG->clr_flags (ACE_Log_Msg::STDERR);
    ACE_LOG_MSG->msg_callback (callback);

    cout << "main" << endl << flush;
    ACE_TRACE ("main");

    pthread_t thId;
    pthread_create( &thId , NULL, my_thread , NULL);

    while (1)
    {
    ACE_DEBUG ((LM_DEBUG, "(%P|%t) <%N %l> main loop debug\n"));
    cout << "main loop cout" << endl << flush;
    sleep(10);
    }
    return 0;
    }


    When I run the application the output is as follows:
    main
    my_thread started
    CALLBACK (25501|1) <My_Use_Callback.cpp 43> main loop debug
    main loop coutmy_thread loop cout

    CALLBACK (25501|1) <My_Use_Callback.cpp 43> main loop debug
    main loop cout
    my_thread loop cout
    CALLBACK (25501|1) <My_Use_Callback.cpp 43> main loop debug
    main loop cout
    my_thread loop cout

    The entry "my_thread loop debug" never appears.

    The same situation is when I use the Logging_strategy configuration.


    Could anyone help?
    Should I initialize my thread in some special way?

    Thanks in advance!
    Tomek

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)