Multithreading in c in mmorpg

I want to use multithreading in my mmorpg in C ++, at the moment I have 5 threads and I want to split the other into two, but my mmorpg server combines a lot of vectors and because arn't threadsafe vectors write, I can’t do it right.

Is there an alternative to using streaming vectors, or is there a way to do multithreaded read / write writes.

Here is an example of what I don't want, try finding an alternative to something like this: Obviously this is not actual code, I'm just doing an example.

//Thread1
//Load monster and send data to the player
globals::monstername[myid];//Myid = 1 for now -.-
senddata(globals::monstername[myid]);//Not the actual networking code, im just lazy.

//Thread2
//Create a monster and manage it
globals::monstername.push_back("FatBlobMonster");
//More managing code i cant be bothered inserting >.<
+5
source share
2 answers

Two things.

  • , . . , , . , 1000 , 10 , 100 . , , . , -, "" - .

  • "/". , . - . , . , . , , , . ,

+6

- . , std::vector std::mutex ( ++ 11):

template <typename T>
class LockedVector {

private:
    std::mutex m;
    std::vector<T> vec;
};

std::lock.

+4

All Articles