#include #include #include #include #include using namespace std; using namespace boost; using namespace boost::asio; using namespace boost::asio::local; void accept(thread::id id) { cout << "accept from " << this_thread::get_id() << ", async_accept from " << id << endl; } void thread_run(shared_ptr &io, shared_ptr &acceptor) { shared_ptr work(new io_service::work(*io)); cout << "start from " << this_thread::get_id() << endl; stream_protocol::socket sock(*(io.get())); acceptor->async_accept(sock, bind(&accept, this_thread::get_id())); io->run(); } int main() { ::unlink("/tmp/fcgi_test.sock"); shared_ptr io_1(new io_service()), io_2(new io_service()); stream_protocol::endpoint ep("/tmp/fcgi_test.sock"); shared_ptr acceptor(new stream_protocol::acceptor(*(io_1.get()), ep, true)); shared_ptr thread_1(new thread(&thread_run, io_1, acceptor)); shared_ptr thread_2(new thread(&thread_run, io_2, acceptor)); thread_1->join(); thread_2->join(); return 0; }