Quote:
|
But then I'm stumped. Because then the main core is sleeping and even if you do have active processes that are handling the new connections, how do you communicate with those processes at a later stage, because the core is still sleeping....
|
What kind of communications do you require, and why do you think that you need to go through your "core" code in order to talk with tasks running in parallel? I suggest that you design your algorithms to take advantage of multi-processing. In that type of design, each task runs as an independent entity or object. Each object is responsible for its own data I/O and need to synchronize resource usage when overlapping tasks vie for the same resource.
An example: Your "core" thread/task does the select and wakes up to accept a connection request from one of your client programs. Once the "core" accepts the connection, it spawns/forks/etc a sub-task that is solely responsible for providing support to the client it is connected with. The main "core" is then allowed to loop back to the select statement and wait for more connections while the sub-tasks are allowed to serve their clients. Depending on what your sub-tasks need to perform, they may even spawn/fork/etc sub-tasks of their own to handle finer granularity actions, etc, etc. Each sub-task needs to run to completion of its assigned functionality and then terminate.
BTW: I pre-apologize if I sound like I am trying to lecture you. There are multiple techniques for accomplishing what you are asking and I am simply trying to have you think in terms of true multi-tasking (in 30 seconds or less)

Please take a look at pthreads, if you are not currently familiar with them, as they make multi-threaded programming very easy.