[omniORB] Multithreading
   
    yashik@veon.com
     
    yashik@veon.com
       
    Mon Nov 18 15:51:02 2002
    
    
  
You can not access non static members/methods ('orb' in your case) from a
static method.
You should either make your 'orb' variable static or get an instance of the
Orb from the CORBA::ORB_init method
For example,
class MyClass
{
private:
     static CORBA::ORB_var orb;
     static void runORB() {
          try {
               cerr << "Server is running!" << endl;
               orb->run();
          }
          catch(...) {
               cerr << "Caught unknown exception." << endl;
          }
     }
public:
     static init(int argc,char* argv[]) {
          orb = CORBA::ORB_init(argc,argv,"omniORB3");
      }
     static void MyClass::startThread() {
     ...
     }
};
...
int main(int argc,char* argv[])
{
     MyClass.init(argc,argv);
     MyClass.startThread();
}
another way could be to change your runOrb:
void runORB() {
     try {
          cerr << "Server is running!" << endl;
          int argc = 0;
          CORBA::ORB_var orb = CORBA::ORB_init(argc,NULL,"omniORB3");
          orb->run();
     }
     catch(...) {
          cerr << "Caught unknown exception." << endl;
     }
}
In this case you should first call   CORBA::ORB_init in main with 'real'
parameters.
Also, you can pass the pointer to your instance as a parameter to the
thread function:
void MyClass::startThread() {
     hThread[0] = CreateThread(NULL,0,MyClass::ThreadFunc,(void*)this,0,
&dwThreadID[0]);
     ...
}
DWORD WINAPI MyClass::ThreadFunc(LPVOID p) // should be static
{
     MyClass* self = (MyClass*) p;
     self->runORB();
}
HTH,
Yakov
P.S.
     This is not a compiled solution
                                                                                                                                 
                    "Uli Syber"                                                                                                  
                    <uli.syber@schraml.de>             To:     omniorb-list@omniorb-support.com                                  
                    Sent by:                           cc:                                                                       
                    omniorb-list-admin@omniorb-s       Subject:     [omniORB] Multithreading                                     
                    upport.com                                                                                                   
                                                                                                                                 
                                                                                                                                 
                    18/11/2002 16:55                                                                                             
                                                                                                                                 
                                                                                                                                 
Hi,
System:
I use omniORB 4.0.0 on a win 32 architecture. My operation system is WIN
2000 and I use VC++ 6.0:
Problem:
Iīd like to start an omniORB server in my program as a background thread
(worker thread). Therefore I have tried the following:
#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
/////////////////////////////////////////////////////////////////////////////////////////////////
class MyClass
{
           private:
                     CORBA::ORB_var orb;
                     static DWORD WINAPI ThreadFunc();
                     void startThread();
           public:
                     void runORB();
};
/////////////////////////////////////////////////////////////////////////////////////////////////
void MyClass::runORB()
{
           try
           {
                     cerr << "Server is running!" << endl;
                     orb->run();
           }
           catch(...)
           {
                     cerr << "Caught unknown exception." << endl;
           }
}
DWORD WINAPI MyClass::ThreadFunc()
{
           runORB();                      //Proplem: Isnīt a static member
because auf orb->run();
           return((DWORD)0);
}
void MyClass::startThread()
{
           hThread[0] = CreateThread(NULL,0,MyClass::ThreadFunc,NULL,0,
&dwThreadID[0]);
           WaitForMultipleObjects(
MAX_THREADS,hThread,TRUE,INFINITE);
           printf("Thread is running!");
}
CreateThread(...) need a static function like MyClass::ThreadFunc
().Threrefore must runORB() in ThreadFunc() actually also a static method.
But in runORB() I call orb->run() witch gets on the heap. Iīve tried to
include CORBA.h to get an instance of ORB_var but it doesnīt work.
Question:
How can I get orb->run() as a background work?
greetings,
Uli
_______________________________________________
omniORB-list mailing list
omniORB-list@omniorb-support.com
http://www.omniorb-support.com/mailman/listinfo/omniorb-list