简体   繁体   English

来自C ++的线程安全SQL Server

[英]thread safe sql server from c++

I have a for loop in c++ parallelized using OpenMP. 我在使用OpenMP并行化的c ++中有一个for循环。 In the loop, I am accessing an sql server database. 在循环中,我正在访问sql服务器数据库。 I have been told that if I share the same ODBC driver between threads, the data access would not be parallel. 有人告诉我,如果我在线程之间共享相同的ODBC驱动程序,则数据访问将不会并行。 If I define different drivers for each iteration, it would be time consuming.(?) Is there a way to have different threads access the same data in a safe parallel manner? 如果我为每次迭代定义不同的驱动程序,那会很费时间。(?)是否有办法让不同的线程以安全的并行方式访问相同的数据?

PS: I am not writing to the database, just reading from it. PS:我不是在写数据库,只是从数据库中读取。

I have been told that if I share the same ODBC driver between threads, the data access would not be parallel. 有人告诉我,如果我在线程之间共享相同的ODBC驱动程序,则数据访问将不会并行。

Are you sure that you have told exactly this? 您确定您已准确告知了吗?

There are lot of issues about multithread, but for most ODBC drivers you can use connection-per-thread model to do reading in parallel. 关于多线程有很多问题,但是对于大多数ODBC驱动程序,您可以使用“每线程连接”模型来并行读取。 So connect each time you start thread (and close when thread is shut-downed). 因此,每次启动线程时都要连接(并在线程关闭时关闭)。 Better pattern will be usage of connection pool. 更好的模式是使用连接池。

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

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