![]() |
|
The following sample program, thread_safe, shows how you can use a cursor across threads. Sample output for this program follows the source listing.
The main thread starts a connection that is named con1 and declares a cursor on table t. It then opens the cursor and makes connection con1 dormant. The main thread then starts six threads (six instances of the threads_all() function) and waits for the threads to complete their work with the pthread_join() DCE call.
Each thread uses the connection con1 and the opened cursor to perform a fetch operation. After the fetch operation, the program makes the connection dormant. Threads use connection con1 in a sequential manner because only one thread can use the connection at a time. Each thread reads the next record from the t table.
The sample output might appear different each time the sample program executes because it depends on the execution order of the threads.
In this output, Thread 1 fetches the last record in the table.