Subject | Using API in Multithreading environment |
---|---|
Author | Martin Morixe |
Post date | 2005-07-03T17:32:48Z |
Hi,
does anyone knows if FireBirds API supports multithreaded calls? I've read
that it does, but I haven't been lucky! My threads blocks when two API calls
are made at same time.
Description:
I have an insert function called by multiple threads:
bool insert (...) {
isc_start_transaction ();
...
isc_dsql_execute_immediate();
...
isc_commit_transaction();
}
The insert function recieves a "context" parameter (each thread has its own
context) from where it gets the db connection, SQLCA parameters,
transactions, etc... (This is: each thread has it own connection, SQLCA
parameters, transaction, etc).
The problem: when any of
isc_start_transaction ();
isc_dsql_execute_immediate();
isc_commit_transaction();
are called by 2 threads at the same time, both threads blocks forever.
I've tried different isolation leves, the no_wait flag when opening the
transaction, etc... but it still blocks.
Workaround: I've put a mutex before each call.... and this way it works....
but it sucks!
bool insert (...) {
globalmutex.lock();
isc_start_transaction ();
globalmutex.unlock();
...
globalmutex.lock();
isc_dsql_execute_immediate();
globalmutex.unlock();
...
globalmutex.lock();
isc_commit_transaction();
globalmutex.unlock();
}
So, it looks like the API is not multithreaded...
BTW:
- The program is compiled using multithreaded library, of course.
- I've tried a lot of combinations, and now I'm using the simplest
(execute_inmediate, and one connection for each thread). Ideally I'd use
prepared_sql and share the same db connection between all threads.
Did any one succeed in a multithreaded environment?
Thanks
Martin
[Non-text portions of this message have been removed]
does anyone knows if FireBirds API supports multithreaded calls? I've read
that it does, but I haven't been lucky! My threads blocks when two API calls
are made at same time.
Description:
I have an insert function called by multiple threads:
bool insert (...) {
isc_start_transaction ();
...
isc_dsql_execute_immediate();
...
isc_commit_transaction();
}
The insert function recieves a "context" parameter (each thread has its own
context) from where it gets the db connection, SQLCA parameters,
transactions, etc... (This is: each thread has it own connection, SQLCA
parameters, transaction, etc).
The problem: when any of
isc_start_transaction ();
isc_dsql_execute_immediate();
isc_commit_transaction();
are called by 2 threads at the same time, both threads blocks forever.
I've tried different isolation leves, the no_wait flag when opening the
transaction, etc... but it still blocks.
Workaround: I've put a mutex before each call.... and this way it works....
but it sucks!
bool insert (...) {
globalmutex.lock();
isc_start_transaction ();
globalmutex.unlock();
...
globalmutex.lock();
isc_dsql_execute_immediate();
globalmutex.unlock();
...
globalmutex.lock();
isc_commit_transaction();
globalmutex.unlock();
}
So, it looks like the API is not multithreaded...
BTW:
- The program is compiled using multithreaded library, of course.
- I've tried a lot of combinations, and now I'm using the simplest
(execute_inmediate, and one connection for each thread). Ideally I'd use
prepared_sql and share the same db connection between all threads.
Did any one succeed in a multithreaded environment?
Thanks
Martin
[Non-text portions of this message have been removed]