[omniORB] static variable & thread

Renny Koshy renny@visualsoft.com
Mon, 6 Mar 2000 12:56:23 -0500


Cedric:

In my project, I dont' use the start() from within the constructor.  I
actually
call it later on in the program.  I should say that my example was bad, and
I 
don't call BLAH->run() , rather BLAH->start();

I can't see why your code doesn't work, assuming you initialize the thread
constructor
in your constructor, similar to the diner example included with the
omniThread.
i.e.

class X : public omni_thread
    X(void *Y) : omni_thread(Y) {
        start();
    }
}

Is this what you do in essence?

-Renny


> -----Original Message-----
> From: cedric charrier [mailto:cedric.charrier@detexis.thomson-csf.com]
> Sent: Monday, March 06, 2000 12:26 PM
> To: Renny Koshy
> Cc: Omniorb-List (E-mail)
> Subject: Re: [omniORB] static variable & thread
> 
> 
> Reading omnithread documentation, I have undertsood it was 
> necessary to
> run start() method in the constructor, and so start() execute 
> the thread
> describe in the run() method.
> 
> I'll try to be more specific :
> 
> >     - I want to develop an application with a client calling
> > > a server which execute threads.
> >
> > Can you be more specific about what you mean, since:
> >         If your client calls the server, omniORB is automatically
> > using threads to process your request (default of upto 5).
> >
> > > So I tried to write like you say a _i class which inherit
> > > from the both _sk class and omnithread class. It seem ok, but
> > > when the constructor tries to execute the run() method of
> >
> > You shouldn't call the run() from the constructor.  Call it from
> > the "thing" that constructs it.  i.e.
> >
> >         .... some code ...
> >
> >         ClassX BLAH = new ClassX(param1,pararm2,parar3);
> >
> >         BLAH->run();
> >
> > > omnithread (calling by start()), the program abort. Perhaps I
> > > have to declare in the IDL file this inheritance with omnithread ?
> > > How can I do that ?
> 
> The following exemple run with omnithread core.
> 
> // declaration of A class
> //*****************
> class A : public omnithread
> {
>     public:
>         static int stateA;
>         int id;
>         A();
>     private:
>          workA();
>         ~A();
>         void run(void* arg);
> };
> 
> // definition of A class
> //***************
> ominimutex A::stateA;
> A::run(void* arg)
> {
>     // Modification of stateA
>     // ....
> }
> 
> A::A() : omnithread()
> {
>     id=0;
> 
>     // running thread
>     start();
>  }
> 
> Now I want to modify it to do this : when the server creates several
> threads of class A (describe in the run() method),  each one of theses
> threads modifies the static variable stateA, and I want that client
> could read the static variable stateA (modified by each 
> thread) in real
> time.
> 
> 
> So I try to modify this code like this :
> 
>  class B_i : public virtual _sk_B , public virtual omnithread
> 
> With the same structure than A class, and at the program 
> execution, when
> start() try to execute run() method, the program abort. But I haven't
> complety finish the implementation (and it could be an other problem),
> so I would like to know if that I want to do is realy possible.
> 
> Thanks for your above example
> 
> Sincerely
> 
> Cedric Charrier
>