C++ の mmorpg でマルチスレッドを使用したいのですが、現時点で 5 つのスレッドがあり、別のスレッドを 2 つに分割したいのですが、私の mmorpg サーバーは多数のベクトルで構成されており、ベクトルはスレッドセーフではないので、私はそれを正しく行うことはできません。
スレッド間でベクトルを使用する代替手段はありますか、またはベクトルを読み取り/書き込みマルチスレッドセーフにする方法はありますか?
私が望んでいないものの例を次に示します。次のようなものに代わるものを見つけてみてください。明らかに、これは実際のコードではありません。例を作成しているだけです。
//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 >.<