Answer the question
In order to leave comments, you need to log in
How can I make a thread run on demand in boost, and not automatically?
Good time!
I am writing a simple server on boost.
In the listener's constructor, I create a boost::thread object and bind it to my handler function.
Why does a new thread start its execution as soon as the boost::thread object is created? Is it possible to make the thread start its execution on demand, and not right away?
thrd_sp = boost::shared_ptr<boost::thread>(
new boost::thread( boost::bind( &listener::dispatch, this )));
Answer the question
In order to leave comments, you need to log in
Actually, what you are doing is what is called an active object (for example, in the Oberon language this is a common thing).
You have the wrong architecture: if you want this behavior (as you write), then:
- you must create a thread not in the constructor and not by inheritance ...
- but with a pointer field to the thread that you will activate with a separate run () method, where and the thread will actually be created and run.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question