Original Post
Hey everyone, I'm currently working on a server status/query tool for an NZ gaming community, and at the moment I've got it to the point where it can query a server and gather info from it (you know, number of players etc). I now want to make it multithreaded so I can query more than one at a time, and also run the GUI frontend fluidly. At the moment I have a class something like this: with player information. Other classes can then grab that information using the get methods. I'm now having trouble working out how to turn this into a safe multithreaded system. I've looked at Boost.Threads and read several threading tutorials, but they've showed me more about the usage of threads as opposed to useful implementation ideas. I haven't had a lot of experience with threads, as I've only ever had to use a single extra thread until now (perhaps I still do?). Mainly I'm just after a bit of direction and maybe a few hints :P Some idea's I've had include writing a thread safe Map class which can be read by the gui and updated by a server query manager, only this makes the above server query class redundant. I've also thought about implementing some kind of thread/server pool (I've heard a bit about semaphores or a mutex + condition variable to achieve this), or writing a thread safe queue for update() to insert it's results into, then for the ServerQuery object to read back out (which seems overly complex). I'm not sure any of these methods are any good, or worth pursuing, but hopefully they show that I've put some thought into this myself before posting. Any help would be great :) [Edited by - CapBBeard on August 27, 2006 10:57:29 AM]
class _rcExport ServerQuery
{
public:
ServerQuery() {}
virtual ~ServerQuery() {}
virtual const std::vector<PlayerData*>& getPlayerData() const = 0;
virtual const ServerData* getServerData() const = 0;
virtual const unsigned long ping() = 0;
virtual void update() = 0;
virtual const std::string& getAddress() const = 0;
virtual const short getPort() const = 0;
};
In the concrete implementations, update() opens a UDP socket to the server, queries it for information, and fills both a ServerData struct and a vector