【问题标题】:Using unixODBC in a multithreaded, concurrent setting在多线程并发设置中使用 unixODBC
【发布时间】:2011-05-11 14:00:44
【问题描述】:

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

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

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

【问题讨论】:

    标签: unixodbc


    【解决方案1】:

    答案,以来自 __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)
     *
     */
    

    【讨论】:

    • 我认为你没有抓住重点。关键是可以显式地设置线程级别以与本身提供某种程度的线程安全的驱动程序一起使用。 myisam 与此无关。
    • @sclv,谢谢! unixODBC 文档非常稀少。 ://
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

      应用程序端不需要线程。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-03-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-11-06
        • 1970-01-01
        • 2011-01-01
        • 2018-03-08
        相关资源
        最近更新 更多