This question is related to: Is it possible to have several ORB objects in the same process?
So, thanks to @BrianKelly I found information about the OR
The ORB will use different connections (and threads) to different servers every time - always. Receiving answers and incomming calls are also handled in different threads (if useful and/or needed).
I think you try try to solve things, that the ORB already has solved for you. It's a middleware, don't scare about threading and stuff. It's already done by CORBA experts.
I found something like a workaround. Makes my code really ugly and not easy for support, but it's still something.
Here's what I did:
ORB_init
)ORB_init
, but it will pass several times the -ORBInitRef
parameter, with different values - one for each thread/connectionORB_init
, they directly execute resolve_initial_references
and continue with the server specific thingsNote: My example does not containt resolve_initial_references
, because the crash is in ORB_init
.
So, applying this "algorithm" for this "workaround" would look like:
#include <OB/CORBA.h>
void* run( void * );
CORBA::ORB_var varORB;
int main()
{
/** The necessary configurations */
//-------------------------------------v
const char* nameservice1 = "NameService1=corbaloc::10.102.8.15:13069/NameService";
const char* nameservice2 = "NameService2=corbaloc::192.168.1.99:13069/NameService";
//-------------------------------------^
/** INIT the ORB **/
int argc = 5; char* argv[ 6 ];
const char* initref = "-ORBInitRef";
const char* exe = "test";
argv[0] = (char*)exe;
argv[1] = (char*)initref; argv[2] = (char*)nameservice1;
argv[3] = (char*)initref; argv[4] = (char*)nameservice2;
argv[5] = NULL;
varORB = CORBA::ORB_init( argc, argv );
pthread_t t1, t2;
char ns_id1 = '1', ns_id2 = '2';
pthread_create( &t1, NULL, run, (void*)&ns_id1 );
pthread_create( &t2, NULL, run, (void*)&ns_id2 );
pthread_join( t1, NULL ); pthread_join( t2, NULL );
varORB->destroy();
return 0;
}
void* run( void* arg )
{
char nameservice[] = "NameServiceN";
// set the right number of the nameservice
nameservice[ 11 ] = *((char*)arg);
varORB->resolve_initial_references( nameservice );
// do some CORBA-specific stuff
printf( "SUCCESS %c\n", *(char*)arg );
return NULL;
}
I still can't believe this is the only option. If you look at my code (in the question) carefully, you'll see, that:
mt == false
)ORB_init
IS synchronizedmt == false
)So, this is not actual answer to my question, it's kind of a workaround.
It doesn't make sense (at least to me) to be possible to create several ORBs in a single thread, but not in multiple threads.