1 Feb
2015
1 Feb
'15
1:52 p.m.
01.02.2015, 19:11, "Aaron Levy"
I've written code of the form:
Code:
io_service svc; io_service::work work(svc);
thread t1( [&svc]() { svc.run(); } ); thread t2( [&svc]() { svc.run(); } ); thread t3( [&svc]() { svc.run(); } );
endpoint ep(ip::tcp::v4(), port); acceptor acceptor(svc, ep);
while (true) { shared_ptr<socket> sock(new socket(svc)); acceptor.accept(*sock);
svc.post( [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.
--
Adding an appropriate library tag to the subject line. -- Aaron Levy aaron.levy@yandex.com