title: Use multiple ORBs through different threads (multithreaded multi-orb client application) - how?
body: <p><sub>This question is related to: <a href="https://stackoverflow.com/questions/12933790/is-it-possible-to-have-several-orb-objects-in-the-same-process"><strong>Is it possible to have several ORB objects in the same process?</strong></a> </sub></p>
  
  <p>So, thanks to @BrianKelly I found information about the <code>ORB</code> identifier (even though there was no such information in all <code>ORBACUS</code> docs, that I have) and I successfully created a simple application, that connects to different <code>CORBA</code> servers and successfully executed several <code>CORBA</code> requests.</p>
  
  <p>So far, so good.</p>
  
  <p>Now, what I want to do, is to make this application multithreaded and to start a separate thread for the connection to the different servers. But <code>ORB_init</code> crashes.</p>
  
  <p>Here's a very short code, that I use for testing:</p>
  
  <pre><code>#include &lt;OB/CORBA.h&gt;
  
  pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
  void* run( void * );
  
  struct config { const char* nameservice; const char* id; const char* exe; };
  
  const bool mt = true;
  
  int main()
  {
      config cfg1 = { "NameService=corbaloc::10.102.8.15:13069/NameService", "1", "test" };
      config cfg2 = { "NameService=corbaloc::192.168.1.99:13069/NameService", "2", "test" };
  
      if( mt )
      {   
          pthread_t t1, t2;
  
          pthread_create( &amp;t1, NULL, run, (void*)&amp;cfg1 ); 
          pthread_create( &amp;t2, NULL, run, (void*)&amp;cfg2 ); 
  
          pthread_join( t1, NULL ); pthread_join( t2, NULL );
      }
      else
      {
          run( (void*)&amp;cfg1 );
          run( (void*)&amp;cfg2 );
      }
  
      printf( "SUCCESS!\n" );
      return 0;
  }
  
  void* run( void* arg )
  {
      pthread_mutex_lock( &amp;mutex );
  
      int argc = 2; char* argv[3];
  
      config* cfg = (config*)arg;
      argv[0] = (char*)cfg-&gt;exe;
      argv[1] = (char*)cfg-&gt;nameservice;
      argv[2] = NULL;
  
      CORBA::ORB_var m_varOrb = CORBA::ORB_init( argc, argv, cfg-&gt;id );
  
      pthread_mutex_unlock( &amp;mutex );
      return NULL;
  }
  </code></pre>
  
  <p>So, when <code>mt</code> is <code>false</code>, everything's fine, I can extend the code to create some server specific objects, to execute different requests, etc. But then <code>mt</code> is <code>true</code>, the second thread fails calling <code>ORB_init</code>. See the stack trace below.</p>
  
  <p>I'm pretty sure that I'm missing something very simple and stupid, but what?</p>
  
  <pre><code>$ g++ -g3 -ggdb -Wall -Wshadow -march=i486 
        -DUNIX -DLINUX -DPTHREADS -DMULTITHREAD -D_REENTRANT
        -I. -I/usr/local/include/OB/ -I/usr/local/include/JTC/ 
        -I/usr/include/OB/ -I/usr/include/JTC/ -L/usr/local/lib 
        -lpthread -lm -lz -lrt -ldl -lOB -lJTC -lCosNaming 
        test.cpp
  </code></pre>
  
  <p>Stacktrace:</p>
  
  <pre><code>#0  0x00566402 in __kernel_vsyscall ()
  #1  0x0080dfd0 in raise () from /lib/i686/nosegneg/libc.so.6
  #2  0x0080f9b1 in abort () from /lib/i686/nosegneg/libc.so.6
  #3  0x03dc490b in ~RefCount 
      (this=Could not find the frame base for "~RefCount".) 
      at ../../include/OB/RefCount_Ts_Linux-x86-32.h:43
  #4  0x03ef8965 in ORBInstance 
      (this=Could not find the frame base for "ORBInstance".) 
      at ORBInstance.cpp:276
  #5  0x03f134fe in ORB_impl 
      (this=Could not find the frame base for "ORB_impl".) 
      at ORB_impl.cpp:281
  #6  0x03f24740 in OBCORBA::ORB_init 
      (ac=Could not find the frame base for 
          "OBCORBA::ORB_init(int&amp;, char**, OB::Properties*, 
                             OB::Logger*, OB::Reactor*, 
                             char const*, char const*)". ) 
      at ORB_init.cpp:994
  #7  0x03f249d9 in CORBA::ORB_init 
      (ac=Could not find the frame base for 
           "CORBA::ORB_init(int&amp;, char**, char const*, char const*)".) 
      at ORB_init.cpp:1014
  #8  0x0804895d in run (arg=0xbfe8b544) at test_server.cpp:45
  #9  0x007334d2 in start_thread () from /lib/i686/nosegneg/libpthread.so.0
  #10 0x008b848e in clone () from /lib/i686/nosegneg/libc.so.6
  </code></pre>