代码之家  ›  专栏  ›  技术社区  ›  sclv

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

  •  6
  • sclv  · 技术社区  · 14 年前

    我要问并回答这个问题,因为我花了很长时间才弄明白,我希望答案是从这里开始的。

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

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

    3 回复  |  直到 14 年前
        1
  •  14
  •   sclv    14 年前

    答案是,以来自}uu 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)
     *
     */
    
        2
  •  3
  •   Nick Gorham    13 年前

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

        3
  •  0
  •   Abhijeet Apsunde    12 年前

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

    应用程序端不需要线程。