简体   繁体   English

从OCCI环境获取连接时,我应该放置关键部分吗

[英]Should I Put Critical Section While Getting Connection from OCCI Environment

I'm writing a multi-threaded application. 我正在编写一个多线程应用程序。 My worker threads get connection from an environment object as follows:. 我的工作线程从环境对象获取连接,如下所示:

//EnterCriticalSection(&cs);
conn = env->createConnection(username, password, connStr);
//LeaveCriticalSection(&cs);

For concurrency, should the connection be created in a critical section or not? 为了并发,是否应该在关键部分中创建连接? Does the env need it? 环保需要吗? And why? 又为什么呢?

Thanks. 谢谢。

If createConnection is thread-safe then you don't need it. 如果createConnection是线程安全的,则不需要它。

If createConnection isn't thread-safe then you do need the critical section. 如果createConnection不是线程安全的,那么您确实需要关键部分。

Consult your documentation to see whether it's thread-safe or not. 请查阅您的文档以查看其是否是线程安全的。 If it doesn't explicitly say it's thread-safe, them play it safe and wrap it in a critical section. 如果没有明确指出它是线程安全的,则他们会安全地将其包装在关键部分。

Edit: Of course, all of the above assumes that multiple threads will be calling createConnection . 编辑:当然,以上所有条件都假定多个线程将调用createConnection If they're not, then obviously you won't need the critical section at all. 如果不是,那么显然您根本不需要关键部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM