[Boost.Thread] Multithreaded Multithreaded Server

Hi, Fairly new to Boost. Bear with me. I'm trying to write a multithreaded multithreaded server (two multithreaded operations): ideally, there should be a single process, containing at least two threads. The first thread handles various tasks (and can start other threads to help it as well). The other thread waits for incoming connections, and adds a new thread for each one: Server process: -Thread 1 (Handle background server operations, etc.) -helper thread 1 -helper thread 2 ... -helper thread *n* -Thread 2 (Listen for incoming connections. When found, make a new connection thread to handle it) -connection thread 1 -connection thread 2 ... -connection thread *n* I began by making heavy use of the example herehttp://www.boost.org/doc/libs/1_36_0/doc/html/boost_asio/example/echo/async_.... Please see my attached files for my implementation. The classes "mMindThreadServerListener" and "mMindServerHandlerClient" correspond to "server" and "session", respectively. "mMindServer" is the highest level (server process). In it, there's a thread group that contains "Thread 1" ("_thread_connection_pruner", which kills unused connections, and represents a background server operation) and "Thread 2" ("_thread_listener", which listens for incoming connections). Thread 2's need to make other threads seems to be handled by boost::asio::io_service. Unfortunately, when a connection is found, Thread 1 stops. I can only attribute this to a lock boost::asio::io_service puts, although I have no idea. Can someone explain what's going on, and possibly a better way to do this? Thanks, Ian

I'm trying to write a multithreaded multithreaded server (two multithreaded operations): ideally, there should be a single process, containing at least two threads. The first thread handles various tasks (and can start other threads to help it as well). The other thread waits for incoming connections, and adds a new thread for each one:
So, for 1000 connection you end up with 1000 threads, don't you?
Unfortunately, when a connection is found, Thread 1 stops. I can only attribute this to a lock boost::asio::io_service puts, although I have no idea.
io_service::run() blocks the thread. You can think of it like a "message loop" -- it runs as long as io_service has completion handlers to dispatch.

On Sun, Apr 10, 2011 at 1:43 PM, Igor R
I'm trying to write a multithreaded multithreaded server (two multithreaded operations): ideally, there should be a single process, containing at least two threads. The first thread handles various tasks (and can start other threads to help it as well). The other thread waits for incoming connections, and adds a new thread for each one:
So, for 1000 connection you end up with 1000 threads, don't you?
Basically. There'd be thread 1 (the server background operations thread), plus any helpers it had (say 0). Then, there'd be thread 2 (listener) and then 1000 connection threads, for a total of (1+0)+(1+1000) = 1002 threads.
Unfortunately, when a connection is found, Thread 1 stops. I can only attribute this to a lock boost::asio::io_service puts, although I have no idea.
io_service::run() blocks the thread. You can think of it like a "message loop" -- it runs as long as io_service has completion handlers to dispatch.
Right, but I wouldn't expect it to block other threads (i.e., thread 1). Thread 2 should block, running in its own little thing, but thread 1 should keep running, right? Or does io_service::run() block *all* threads in the process? Thanks, Ian
participants (2)
-
Ian Mallett
-
Igor R