
Does it still crash if you remove the call to service.stop()? Because in the code below, that should be redundant.
Also, starting the threads should occur *after* you post all the tasks. Otherwise there is a chance that none of them will actually execute.
Thanks for your comments.
As Igor pointed out in another email, without a call to service.stop(), the io_service will continue to wait for more handlers which means the group.join_all() will continue to wait uninterrupted until the Sun finally explodes.
Just out if curiosity, if you create io_service::work dynamically and destroy it instead of stopping io_service, does it crash? Like this: auto work = make_shared<io_service::work>(service); //.... // at the point where you want to stop the service: work.reset();