|
Boost Users : |
Subject: [Boost-users] [asio] Using io_service for synchronous tcp accept + custom tasks
From: Aaron Levy (aaron.levy_at_[hidden])
Date: 2015-02-01 08:52:28
01.02.2015, 19:11, "Aaron Levy" <aaron.levy_at_[hidden]>:
> 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_at_[hidden]
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net