The goal is to develop something similar with a quiz application: there is a server to which players connect. At some point, a game is started. The game consists in asking the players a few multiple answer questions and determining the winner based on some criteria.
The server spawns a new thread for each client (I know it might be better and easier to use select, but the point is to understand/learn multithreading). The users are "pending" until a sufficient number of users are available such that the game can start.
The problem is what happens when the game starts? My current best approach is to use a lot of shared data that is constantly pooled by all threads and spawn a game controller thread that controls the game.
More specifically, I would have a data structure Player that has some flag inGame. When sufficient players are available, the player that notices this starts the game control thread and passes the available players to it. The game control thread marks all available players as being "inGame" and assigns a question to them. After some time, it checks for an answer. In the meantime, the players constantly check for updates from the game control thread.
I feel that this shared data approach is not the best. Do you have any suggestion on how could I improve the architecture of my application?