[omniORB] static variable & thread

cedric charrier cedric.charrier@detexis.thomson-csf.com
Mon, 06 Mar 2000 18:25:58 +0100


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