0

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" .

Lucifer
  • 49
  • 5
  • 1
    The problem is, most likely, that you don't wait for the thread to actual finish., so the process exits before the thread have any time to run. You need to wait for the thread to finish. – Some programmer dude Apr 10 '15 at 08:52
  • 1
    If you *don't* want to wait for the thread, you need to detach is (using e.g. the `THR_DETACHED` flag). – Some programmer dude Apr 10 '15 at 08:57
  • 十分感谢您解决了我的问题!!I try to add "ACE_Thread_Manager::instance()->wait();" I got what I want – Lucifer Apr 10 '15 at 08:58

1 Answers1

1

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();
Johnny Willemsen
  • 2,942
  • 1
  • 14
  • 16