Originally posted by Karen Baog:
Thread1:
Listen indefinitely until packet is received
Packet finally received, so process
yield so other thread can run
You realize that since this code blocks on the call to receive(), that yield() doesn't get invoked until AFTER a packet is received? Being nice to other threads is a Good Thing, but since receive() blocks, another thread would get control immeditately if there were no data to be processed.
Originally posted by Karen Baog:
The problem I see with the above "approach" is that it is not a good approach, for the resource to be tied up until a packet is received is such a waste.
Like I said above, unless you have thousands of simultaneous connections, this won't be a problem. You could use a low-latency protocol where the client only connects when it has a request (HTTP works this way), to reduce the amount of time a client connection blocks a thread.
NIO's always an option. I haven't done much with it. There's an article on
Building Highly Scalable Servers with NIO but like I said before, if you run into trouble, there's not a lot of experience with NIO in the community.