Subject Re: fbclient and thread-safety
Author David Rushby
--- In, "precari0" <douglas@...> wrote:
> - Thread T1 creates connection C1 and uses it for some select/update.
> - C1 returns to the pool, waiting for new requests.
> - Thread T2 uses C1 for some operations.
> - C1 is in use by T2, a new request arrives.
> - Now T3 creates C2 and uses it for some operations.
> - C1 returns to the pool.
> - C2 returns to the pool.
> Is this sequence correct from a thread-safe perspective? Should it
> work?
> If this kind of sequence goes on for a while, the "invalid request
> handle" appears. But if I change my app so that every thread gets
> its own unique connection, the problem doesn´t happen.

What you're doing appears to be sound, but it will only work with
certain Firebird version/operating system/protocol combinations. Some
fbclient configurations allow a single connection to be used serially
by multiple threads (that's what most people mean when they say
"thread-safe per-connection"), while other configurations require more
restrictive serialization.

There's a general overview of fbclient thread-safety here:

I don't use Delphi, so I can't comment on whether there are any
threading issues specific to the Delphi components you're using.