POCOs HTTPTimeServer example has a sequence in the HTTPTimeServer::main() function that says:

HTTPServer srv(new TimeRequestHandlerFactory(), svs, pParams);

srv.start();

waitForTerminationRequest();

srv.stop();

As I understand it, waitForTerminationRequest() waits for Ctrl-C or a kill signal. This would mean that the srv.stop() part of the function is never reached.

I'm looking for a way to wait for the server thread (started by srv.start() ) to finish and then continues with the execution, so I can cleanly shut down other stuff.

Do you have a suggestion ?

terminate() seems to just send a kill signal, and code beyond waitForTerminationRequest is never reached.

I have also tried to set a mutex in the constructor, then try to lock the mutex right before srv.stop() , which of course blocks. The idea was to release the lock as last action of the server thread. However, for reasons I do not understand, this does not work.

before waitForTerminationRequest()
after waitForTerminationRequest()
before srv.stop()
after srv.stop()
Press any key to continue . . .

> I'm looking for a way to wait for the server thread (started by srv.start() ) to finish and then continues with the execution, so I can cleanly shut down other stuff.
>
> Do you have a suggestion ?

Since srv.stop() is reached, there lies the answer.

> terminate() seems to just send a kill signal, and code beyond waitForTerminationRequest is never reached.

I wanted to double-check this, so I ran it in debugger (MS Visual Studio 8) and it does reach srv.stop(). If the debugger complains about ctrl-c (can be disabled in IDE settings), just choose "continue" and application will exit cleanly.

> I have also tried to set a mutex in the constructor, then try to lock the mutex right before srv.stop() , which of course blocks. The idea was to release the lock as last action of the server thread. However, for reasons I do not understand, this does not work.

There may be some other reason for your troubles (hard to tell without seeing all the code), but it is not the one stated in this post.