Hi,

I'm trying to create a multiplayer game and I'm wondering if it will be useful to use threads and also how to use them.

There would be the following actions in the game (on linux server):
1) server checking if clients are still connected
2) collision detection
3) processing players' input
4) sending the result data to clients
5) ... and probably many more

My questions are:
1) How many threads can be created? (I know that if there is too many, they have to wait for their turn, but is there a limit?)
2) Lets say I would create a new thread for each player (let's say 1000 or more). I suppose it makes no sense, but would than the switching between threads be very time consuming?

Bye

I don't think that creating a new process for every player is the right approach in your case. In order to manage your threads correctly you have to do a bunch of shared data checking (google locks, semaphores, atomic operations). This will take some of the processors time every time a context switch has been made, so having thousands of threads is not optimal.

I'm pretty sure that you should be able to do just fine with just 3-4 threads. One or two threads for sending/receiving data, one timed thread for calculating physics, and one thread running at processor's speed for drawing and playing music.

>>How many threads can be created? (I know that if there is too many, they have to wait for their turn, but is there a limit?)

Windows 2000: maximum is 65,535 handles. That will include threads, files handles, GDI object handles, etc. I have not found if XP, Vista or Win7 are any different.

Edited 6 Years Ago by Ancient Dragon: n/a

Thanks.

And is switching between threads time consuming?

This article has been dead for over six months. Start a new discussion instead.