我會問這個問題並回答這個問題,因爲它花了我一直的時間來弄清楚,我希望答案在這裏開始。在多線程的併發設置中使用unixODBC
問題:一個長時間運行的unixODBC查詢會阻止來自同一應用程序的所有其他人。
問題:如何防止這種情況發生。
我會問這個問題並回答這個問題,因爲它花了我一直的時間來弄清楚,我希望答案在這裏開始。在多線程的併發設置中使用unixODBC
問題:一個長時間運行的unixODBC查詢會阻止來自同一應用程序的所有其他人。
問題:如何防止這種情況發生。
答案以__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)
*
*/
只是該答案的補充。當前版本的unixODBC 2.3.0默認爲Threading = 0,所以默認現在是假設驅動程序是線程安全的。這在過去的幾年中是一個冒險的假設,而不是現在這麼多。
Debian 6仍然使用2.2。 – 2012-05-23 05:19:51
如果您的驅動程序支持異步功能,則可以啓用它並在異步模式下執行耗時的功能。
應用程序端不需要線程。
停止使用myisam? – 2010-11-17 17:51:23
我想你錯過了這一點。重點是可以明確設置線程級別,以便與驅動程序一起提供某種程度的線程安全性。 myisam與此無關。 – sclv 2010-11-18 02:01:03
@sclv,謝謝! unixODBC文檔非常稀少。 :/ – 2012-05-23 05:38:01