简体   繁体   中英

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.

If createConnection isn't thread-safe then you do need the critical section.

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 . If they're not, then obviously you won't need the critical section at all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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