Multiple threds accessing single TZquery object

In this forum we will discuss things relating the ZEOSLib 6.6.x stable versions

Moderators: gto, EgonHugeist

Post Reply
Wild_Pointer
Expert Boarder
Expert Boarder
Posts: 164
Joined: 18.03.2008, 13:03
Contact:

Multiple threds accessing single TZquery object

Post by Wild_Pointer »

Hello,

recently I've been developing application witch is listening for some port ( TIdTCPServer indy component), getting XML and updating DB according to the XML. For that I created 1 query object that I would pass SQL to. Also I'm using timer to check if there are changes in DB from time to time (using the same TZQuery component). The program seemed to work, but after 12 hour or so I get access violations at ntdll.dll .
Now what I changed - as indy creates thread for reading from socket buffer I create separate TZQuery object to be used only in this thread and then free it. This did the trick and now for 3 days the program is running without errors.
The question would be - is it safe to use single query with multiple threads (I guess not), why, and what could be done not to raise access violations in such cases?

ZeosLib 6.6.6, Delphi 2006, Postgresql 8.4, WinXP
Wild_Pointer
Expert Boarder
Expert Boarder
Posts: 164
Joined: 18.03.2008, 13:03
Contact:

Post by Wild_Pointer »

Guess I was too quick to be happy. :(
Maybe I have to create a separate TZConnection for every thread?


2010-01-25 08:54:40 - Event XML parsing error: Access violation at address 0192E459 in module 'LIBEAY32.dll'. Read of address BDA9968C
2010-01-25 08:54:40 - EventServer: Disonnected 192.168.7.201 : 62540
2010-01-25 08:54:50 - Access violation at address 7C90FF56 in module 'ntdll.dll'. Read of address 01A30586
2010-01-25 08:55:00 - Access violation at address 01857DA2 in module 'libpq.dll'. Write of address 01A3E3B8
2010-01-25 08:55:10 - Access violation at address 01857DA2 in module 'libpq.dll'. Write of address 01A3E3B8
2010-01-25 08:55:20 - Access violation at address 01857DA2 in module 'libpq.dll'. Write of address 01A3E3B8
2010-01-25 08:55:30 - Access violation at address 01857DA2 in module 'libpq.dll'. Write of address 01A3E3B8
2010-01-25 08:55:40 - Access violation at address 01857DA2 in module 'libpq.dll'. Write of address 01A3E3B8
User avatar
Pitfiend
Senior Boarder
Senior Boarder
Posts: 68
Joined: 12.12.2009, 07:27

Advanced Knitting...

Post by Pitfiend »

Because working with threads implies you need to knit some stuff, I'll share with you a bit of usefull knowledge. Maybe it can helps you to get your stuff to work better.
You do not have the required permissions to view the files attached to this post.
Wild_Pointer
Expert Boarder
Expert Boarder
Posts: 164
Joined: 18.03.2008, 13:03
Contact:

Post by Wild_Pointer »

Hello, all

from http://www.postgresql.org/docs/8.4/stat ... ading.html I found out, that:
"One thread restriction is that no two threads attempt to manipulate the same PGconn object at the same time. In particular, you cannot issue concurrent commands from different threads through the same connection object. (If you need to run concurrent commands, use multiple connections.)"

That means that you have to have separate TZConnection objects for every thread in your application. That solved my problem of program instability.

Hope others will spend less time looking for the reason of AV errors that happens "out of the blue" :)
Post Reply