Boost logo

Boost Users :

Subject: [Boost-users] Using io_service for synchronous tcp accept + custom tasks
From: Aaron Levy (aaron.levy_at_[hidden])
Date: 2015-02-01 08:41:56

I've written code of the form:


io_service svc;
io_service::work work(svc);

thread t1( [&svc]() {; } );
thread t2( [&svc]() {; } );
thread t3( [&svc]() {; } );

endpoint ep(ip::tcp::v4(), port);
acceptor acceptor(svc, ep);

while (true) {
  shared_ptr<socket> sock(new socket(svc));
  acceptor.accept(*sock); [sock]() { /* do stuff on sock here */ });

Is this way of using io_service for accepting tcp connections and also as a thread pool for serving connected clients valid or could I hit some undefined behavior.

Aaron Levy

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at