Search code examples
c++ace

ACE thread manager can not invoke function


I want to create a thread with ACE_thread_manager, there is no error when I debug. but the result is not right. The function did not work; code like this:

#include "ace/OS.h"
#include "ace/Log_Msg.h"
#include "ace/Thread_Manager.h"
#include <iostream>

void thread_start(void* arg)
{

    std::cout << "Running thread..\n";
}

int main(int argc, char *argv[])
{ 
    ACE_Thread_Manager::instance()->spawn(ACE_THR_FUNC(thread_start), 0, THR_NEW_LWP);      
    return 0;
}

enter image description here this demo should print "Running thread.." , but when I debug it ,it print nothing . These Chinese mean "Please press any key to continue" .


Solution

  • You have to wait in your main until your workers threads have finished. As you say, you have to add the following line before the return in main.

    ACE_Thread_Manager::instance()->wait();