I’m writing a mud, and I’ve got it to a point where people can connect and walk around and all sorts of fun stuff. I’m having a little conceptual trouble with how to communicate between two threads. It actually works, but I don’t understand enough about what I’m doing to know if it will always work, or if I’m doing something which may hurt me later. Working between multiple threads is new to me, and I’m wondering if it might just be easier to go single threaded.
Basically, what I’m doing is as each client finishes receiving a completed line of text, that text is put into a command queue for that client. Then the other thread goes through all the clients, checks if they have a command, and if they do processes it. I’m already aware that the client list may change in the middle, so I’m thinking I’ll have to use a separate list to hold clients with commands pending. But the queue for each client is synchronized, so I don’t think moving the commands between threads is a problem. And while the client does change during the course of the program, the parts the world model uses and the parts the server uses are pretty separate, such that I don’t think either one will step on the other’s toes.
Basically, I’m asking if this approach will work, of if there is a better approach to this problem out there? I’m new to both multiple threads and to network programming, so I’m really in over my head and pretty unsure about everything.