接続を取得中に手動でmongocxx :: poolをロックする必要がありますか?MongoDB C++:mongocxx :: poolスレッドは安全ですか?
つまり、これは安全ですか? (Mongoのウェブサイトの例)
mongocxx::instance instance{};
mongocxx::pool pool {mongocxx::uri{}};
using mongocxx::pool::entry = std::unique_ptr<client, std::function<void (client*)>>
auto threadfunc = [](mongocxx::client &client, stdx::string_view dbname) {
client[dbname]["col"].insert({});
}
// don't even bother sharing clients. Just give each thread its own,
std::thread([]() {
// pool.acquire() returns a mongo::pool::entry type
mongocxx::client *c= pool.acquire().get();
threadfunc(*c, "db1");
threadfunc(*c, "db2");
});
std::thread([]() {
mongocxx::client *c = pool.acquire().get();;
threadfunc(*c, "db2");
threadfunc(*c, "db1");
});
@xcoratあなたが質問したことに対して最高の答えをアップヴォートしたり受け入れたりするのは丁寧です。 – acm
そう!私はちょうど答えを読む:p(jk、ええ、ちょうどそれを読んで、ありがとう:) – xcorat
そして、ええ、私はあなたがそれを修正した方法に正確に私のコードを変更して終了し、質問を編集したと思ったが、 't。再度、感謝します! – xcorat