[omniORB] Hello and Native NT Thread problem [Update]

Saroj Mahapatra saroj@Bear.COM
Mon, 20 Apr 1998 14:19:11 -0400


[snipped]

I just realized that even with the third solution (ThrThread is a class
template), it will be more convenient to have a low
level interface  (as in the first solution):

    template <class Action>
    class ThrThread
    {
     public:
          typedef void* (*StartFunction)(void* arg);
          ThrThread(StartFunction start_func, void* arg, Thr::DetachState
detach_state);   // low level
          ThrThread(Action* start_action, Thr::DetachState detach_state, bool
destroy_action);
           ....
    };

Here is a realistic example used for Orbix thread-per-request filter:

class ThreadPerRequest : public CORBA::ThreadFilter
{
private:
    virtual int inRequestPerMarshal(CORBA::Request& req, CORBA::Environment&) {
         ThrThread<ThreadPerRequest> thread(continue_dispatching, &req,
Thr::detached);
          return -1;
    }
    static void* continue_dispatching(void* arg) {
       CORBA::Orbix.continueThreadDispatch(*(CORBA::Request*)arg);
       return 0;
    }
};

Without this low-level interface, we have to write:

struct DispatchAction {
    CORBA::Requst& req_;
     void* run() {
         CORBA::Orbix.continueThreadDispatch(req_);
         return 0;
     }
     DispatchAction(CORBA::Request& req) : req_(req) {}
};

class ThreadPerRequest : public CORBA::ThreadFilter
{
private:
    virtual int inRequestPerMarshal(CORBA::Request& req, CORBA::Environment&) {
         // we have to create a separate DispatchAction object for every request;
we could not keep
         // req as a member variable.
         ThrThread<DispatchAction> thread(new DispatchAction(req), Thr::detached,
true /* destroy */);
         return -1;
    }
};

* Thread-Per-Request may be a bad idea, but that is beside the point.  Without
the low-level interface, we had
   to allocate a new object on the heap for every request. That is bad!


- Saroj Mahapatra




***********************************************************************************
Bear Stearns is not responsible for any recommendation, solicitation, offer or
agreement or any information about any transaction, customer account or account
activity contained in this communication.
***********************************************************************************