That's my first post :D I've surfed the net for some days to find an answer to what's written on the title, but found only solutions that doesn't apply to my problem (examples are mutex, locking algorithms and some non blocking ones)... My problem is: I'm building a multiplayer videogame that I will use for my last exam in high school, using c++ and SFML, but I really cant find a way to synchronize all my threads. Currently, my program works with a "big" game thread, the thread that every cycle updates all the variables like player's positions, bullets etc and one thread per client, that handle the tcp-socket I/O with SFML (I could do it with standard sockets too but I like them), and every client thread has to read the current status of the game in order to send the data to the player. But if the game thread is modifying the data while one of the client thread is reading it, this obviously results in a segmentation fault. With X number of clients (basically, my objective is to handle all possibles clients limited on my machine power, so they can be 10 as well as 1000), how can I synchronize all their threads with the game thread? If I use mutex or other blocking algorithms, there's no need to use more thread than one. At the end of the game cycle, I could just send and receive by all the clients the data. But this, slows everything, much more than the multithreading system does. One client with slow connection could slow everything. What can I do? One big thread always active modifying everything that must not be stopped, and hundreds of other little threads that have to read the big-thread data in real time. Thanks anyway! If somehow I missed a question thread that explained this, please link that to me. (P.s. The only important thing that I'm using with SFML is the graphic system, examples with winsock/linux ones are good as well. I'm using the c++11 threads) Sorry for my english :c I did my best...
Aucun commentaire:
Enregistrer un commentaire