在多线程并发设置中使用unixODBC

时间:2010-11-17 17:47:12

标签: unixodbc

我要问并回答这个问题,因为我花了很长时间才弄清楚,我希望答案一直在这里开始。

问题:一个长时间运行的unixODBC查询阻止来自同一个应用程序的所有其他查询。

问题:如何阻止这种情况发生。

3 个答案:

答案 0 :(得分:14)

答案,以__handles.c的剪切和粘贴评论的形式 - 我知道,为什么不是每个人都想在那里寻找文档,对吧?

/*
 * use just one mutex for all the lists, this avoids any issues
 * with deadlocks, the performance issue should be minimal, if it
 * turns out to be a problem, we can readdress this
 *
 * We also have a mutex to protect the connection pooling code
 *
 * If compiled with thread support the DM allows four different
 * thread strategies
 *
 * Level 0 - Only the DM internal structures are protected
 * the driver is assumed to take care of it's self
 *
 * Level 1 - The driver is protected down to the statement level
 * each statement will be protected, and the same for the connect
 * level for connect functions, note that descriptors are considered
 * equal to statements when it comes to thread protection.
 *
 * Level 2 - The driver is protected at the connection level. only
 * one thread can be in a particular driver at one time
 *
 * Level 3 - The driver is protected at the env level, only one thing
 * at a time.
 *
 * By default the driver open connections with a lock level of 3,
 * this can be changed by adding the line
 *
 * Threading = N
 *
 * to the driver entry in odbcinst.ini, where N is the locking level
 * (0-3)
 *
 */

答案 1 :(得分:3)

只是对这个答案的补充。 unixODBC 2.3.0的当前版本默认为Threading = 0,因此现在默认假设驱动程序是线程安全的。这是过去几年的风险假设,而不是现在。

答案 2 :(得分:0)

如果您的驱动程序支持异步功能,则可以在异步模式下启用它并执行耗时的功能。

应用程序端不需要线程。