Shared connection over multiply threads

2019-01-26 17:05发布

问题:

Is it possible to create pointer of DBClientConnection and use it in multiply threads?

connection = new DBClientConnection();
connection->connect("localhost");

Then use connection in thread.

Is it safe to access to connection simultaneously?

回答1:

No. DBClientConnection is not thread safe and should not be shared with more than one thread. You might also want to check ScopedDbConnection, which is backed by a connection pool and closes the socket for you upon destruction.



标签: c++ mongodb