Archived

This forum has been archived. Please start a new discussion on GitHub.

Thread problem

Hello,

I have a problem about using Ice to encapsulate some database operation api, like open(), readdata(), close().

The database api require call attachdb() before visit database in thread different to the thread call open() , and call detach() when leave the thread. How can I encapsulate these details with Ice?
I know that in default there's only one service thread beside the main thread. I plan to call open() in the main thread. But where can i detect the begin and the end of thread to call attach()/detach() operation?
May someone give me any advice?

Comments

  • bernard
    bernard Jupiter, FL
    Hello,

    Your database seems a bit unusual (calling open in one thread, attach/detach in other threads); for example with XA, you would call xa_open, xa_start, xa_end from the same thread.

    You can insert code in the dispatching thread before and after the operation by using a Servant Locator: see "29.6.3 Threading Guarantees for Servant Locators" in the Ice manual.
    For example you could attach in locate() and detach in finished().

    If you need to detect whether a thread has been initialized or not, you could use thread-specific data or maintain your own map thread-id to someInfo.

    Cheers,
    Bernard