2010-11-17 5 views
5

Ich werde diese Frage stellen und beantworten, weil es mich für immer brauchte, um herauszufinden, und ich wünschte, die Antwort wäre hier zu Beginn gewesen.Verwenden von unixODBC in einer Multithread-Einstellung

Das Problem: Eine lang laufende unixODBC Abfrage blockiert alle anderen aus der gleichen Anwendung.

Die Frage: Wie verhindert man dies geschieht.

Antwort

12

Die Antwort, in Form eines Ausschneiden-und-Einfügen-Kommentars von __handles.c - Ich weiß, warum nicht jeder denkt, dort nach Dokumentation zu suchen, oder?

/* 
* 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) 
* 
*/ 
+0

aufhören mit myisam ?? –

+0

Ich denke, Sie haben den Punkt verpasst. Der Punkt ist, dass man die Threading-Ebene explizit so einstellen kann, dass sie mit Treibern arbeitet, die selbst ein gewisses Maß an Thread-Sicherheit bieten. Myisam hat damit nichts zu tun. – sclv

+0

@sclv, danke! Die Dokumentation von unixODBC ist schockierend spärlich. :/ –

3

Nur eine Ergänzung zu dieser Antwort. Die aktuelle Version von unixODBC 2.3.0 ist standardmäßig auf Threading = 0 gesetzt, so dass der Standard nun davon ausgeht, dass der Treiber Thread-sicher ist. Dies war eine riskante Annahme in den vergangenen Jahren, nicht so sehr jetzt.

+0

Debian 6 verwendet immer noch 2.2. –

0

Wenn Ihr Treiber asynchrone Funktionen unterstützt, können Sie ihn aktivieren und zeitraubende Funktionen im asynchronen Modus ausführen.

Keine Gewinde auf der Anwendungsseite erforderlich.