0

I currently have something like this

This is a member of my class

 boost::shared_ptr<boost::thread_group> my_group;

Somewhere else in my code I do this

my_group->create_thread( boost::bind( &Myclass::method, this ) );

Now in the above statement is there a way for me to block/wait till this thread has started ? such as

wait for above thread to lauch and start

Do next stuff after that. 
Rajeshwar
  • 11,179
  • 26
  • 86
  • 158
  • A shared flag maybe? Your spawned thread can set a flag, and your main thread spin waits for the flag to change. – BlamKiwi Nov 30 '14 at 21:33

1 Answers1

0

So, as documentation says:

Postcondition: this->size() is increased by one, the new thread is running.

after calling this member function your thread is already running. You can do your next stuff right after that.

grisha
  • 1,247
  • 1
  • 14
  • 20
  • 1
    However, crucially, if your thread's entrypoint sets some mutex that you're relying on at your call site (and why else would you care whether the thread has begun execution?), that may not have been done yet. [This is where it gets complicated](http://codereview.stackexchange.com/q/9431/2503). – Lightness Races in Orbit Nov 30 '14 at 21:35