Subject Multi-thread issues
Author personalsoft_fabiano
Hi all,

I wrote a test application wich creates some threads, each one with a
TIB_Session, TIB_Connection, TIB_Transaction and TIBOQuery, all
created inside the 'Execute' thread method.

These threads executes the same query on the same database, and then
close and free the connection. These threads was designed to be
totally independent and doesn't interact with VCL components, so there
is no synchronized methods or critical sections inside then.

Inside the 'Execute' method, i am logging the execution times to
measure the performance when executing queries in paralel this way:

procedure Execute;
begin
- create the session
- create the connection
- create the transaction
- create the query
- log current timestamp to file
- open the query
- log current timestamp to file
- close the query
- close and destroy the created stuff
end

The test application launches 15 threads, and looking at the result
times i'm noting a behaviour i didn't expect:

Although all threads are runing in paralel, the open and close times
of the thread queries are serialized (i.e. the query from the second
thread only opens after the query of the first query is closed, and so
on. Look the result (the number after DEBUG is just a random number to
distinguish the threads):

DEBUG - 0 - 02:47:55.101
DEBUG - 0 - 02:47:55.661
DEBUG - 31 - 02:47:55.863
DEBUG - 31 - 02:47:56.411
DEBUG - 861 - 02:47:56.630
DEBUG - 861 - 02:47:57.174
DEBUG - 202 - 02:47:57.495
DEBUG - 202 - 02:47:58.021
DEBUG - 272 - 02:47:58.428
DEBUG - 272 - 02:47:58.984
DEBUG - 671 - 02:47:59.319
DEBUG - 671 - 02:47:59.869
DEBUG - 318 - 02:48:00.085
DEBUG - 318 - 02:48:00.670
DEBUG - 161 - 02:48:01.026
DEBUG - 161 - 02:48:01.594
DEBUG - 372 - 02:48:01.923
DEBUG - 372 - 02:48:02.509
DEBUG - 425 - 02:48:02.838
DEBUG - 425 - 02:48:03.405
DEBUG - 82 - 02:48:03.578
DEBUG - 82 - 02:48:04.123
DEBUG - 474 - 02:48:04.293
DEBUG - 474 - 02:48:04.820
DEBUG - 70 - 02:48:05.271
DEBUG - 70 - 02:48:05.839
DEBUG - 840 - 02:48:06.172
DEBUG - 840 - 02:48:06.733
DEBUG - 59 - 02:48:07.057
DEBUG - 59 - 02:48:07.603

I expected that all queries should run at the same time, and the
finish order would be randomic but at almost the same time also.

Do someone have a clue about what can be the cause of this problem?

Regards,

Fabiano.