Home Comments

thread per object

HarvinderHarvinder Member
Hi,
Does ICE support a thread per object paradigm?
Thanks
-
Best regards,
Harvinder

Comments

  • michimichi Member Michi HenningOrganization: Triodia TechnologiesProject: I have a passing interest in Ice :-) ✭✭✭
    No, not as a built-in threading model. We debated whether we should add additional threading models for quite some time. In the end, we decided that we would not because, from our previous CORBA lives, we knew that a lot of confusion and support problems came from incorrect threading model choices.

    Generally, thread-per object isn't all that useful, except maybe if you want to do things in the implementation that are sensitive to thread identity or context.

    If you really want a thread per object, you can do this fairly easily yourself: create a thread in the object's constructor and, whenever an invocation comes along, pass the work to that object's thread and suspent the invocation thread until the operation is complete (if you are using synchronous dispatch; with AMD, you can release the invocation thread and complete the operation in the object's thread). Finally, when the object is destroyed, destroy it's thread as well.

    Depending on your situation, there may be other ways of achieving what you want, such as delaying thread creation until the first invocation, or picking threads out of an idle pool instead of creating a new thread for each object.

    Cheers,

    Michi.
  • HarvinderHarvinder Member
    Thanks for the reply michi, I was thinking on the same line and found some code snippet to make use of workitems and waitqueues under $ICE_HOME/src/IcePack/WaitedQueue.[cpp/h].

    Is there any code snippet/examples which can be used to release the invocation thread and do the job in the object's thread?
  • michimichi Member Michi HenningOrganization: Triodia TechnologiesProject: I have a passing interest in Ice :-) ✭✭✭
    Have a look at the async chapter in the doc. With AMD, you can release the invocation thread and then, later, complete an operation from a different thread by calling ice_response() or ice_exception(). That should give you what you need.

    Cheers,

    Michi.
Sign In or Register to comment.