Informix support for multiple threads in a process to operate on the database at the same time, multiple threads can either use multiple database connections, multiple threads can share a database connection.
In either way, all require careful analysis and processing multi-threaded shared variables lock, unlock processing.
In this paper, the EC multi-threaded program that several issues:
1, compiled connection
Ec when only a complete file, you can use ESQL to-thread option, ESQL will automatically compile informix connection thread-safe libraries.
When there are multiple files, including ec, c, C files, you can first use the-c and ESQL-thread option to compile the file ec. O files, then use the connector to force the connecting thread safe libraries (th library) .
In conclusion requires the following:
A, ESQL-thread option to add
B, configure the environment variables THREADLIB = POSIX
C, to ensure that the connection is thread-safe libraries.
2, multiple threads sharing a connection
Multiple threads sharing a connection, well after the connection is established, you can use a thread
EXEC SQL set connection 'con' dormant;
Placed in dormant status of the connection, then the connection can be activated by other threads.
EXEC SQL set connection 'con';
) While ((sqlca.sqlcode == -1802));
The connection activated, this time can access the database, and only this thread can access the database.
This thread will be connected only set to dormant before it can be used by other threads.
3, multiple threads using multiple connections
A, where each thread requires its own connection to the name of each connection name must be different.
B, must carefully deal with exclusive access to shared variables.