how to obtain a persistent oracle connection in proc*c pthread

Hi all,
I have problem to set up a persistent oracle connection in child thread.
We have a massive batch process dealing with large data. Application was written and impossible to be rewritten. I am trying to extract the most time consuming data fetching and put it into a dedicated child thread.
So main thread will only process(including quick fetch from DB) and child can constantly fetch. Data will be flushed from child to main by global variables.
However I can't see any way to obtain a dedicated DB connection in pthread child.
I got core when main and child both try to access DB.
I tried using context, allocate different context to main and child, but not working, still same core. :mad:
If I stop main accessing DB, then child is fetching continuously.

Can some one help me out or give some code I can refer to?

Thanks in advance!

One easy way - Use IPC - create separate processes. Oracle uses coprocesses in Pro*C. That means your child thread and the main program are actually trying to get the coprocess to run fetches at the same time.

Map a big chunk of shared memory. Start your fetcher as one process, start main as another.
Have main feed fetch requests to the fetcher process , fetcher returns the data. All via shared memory.

Also consider running your old main code as a group of processes. Suppose you are processing items 1000 - 9000.
Start old main with parms 1000-1999, run it in the background. Start old main in the background again with parms 2000-2999, and so on. Call wait for all the processes to complete. This is 'sort of' threading.

Thanks for prompt reply, we can't use the second option due to many existing facilities in this batch will require the batch to be finished in 1 process.
I am very interested in using IPC, where can I see any sample code of IPC? Do you mean fork?
Thanks!

Thanks Jim, the implementation was very successful, I did it by separate the fetcher out as a new process that you mentioned as the first option.
Fetcher always fetches before main needs, then main flush fetched data from IPC.
Performance is improved by 40%.
Appreciate your help!