Re: ORBit2.8.3 thread problem



Well, now your problems is easily reproduced and can be solved. The main
idea is that you should be carefully, when you share memory (global
variables) between threads. You have two global variables - global_orb
and echo_client. Global orb is nicely shared because you create it with
"orb-local-mt". It is done in ORBit library. But nobody will manage
locking of echo_client structure. You should do it yourself. I mean that
to solve your problem you should either create echo_client instance in
each thread (then you can share only IOR string, which is constant) or
lock it with mutex during usage of Echo_echoString. I prefer first
solution.

You can look at echo-client-t.c example in ORBit-2.10/test directory, to
see proper example.

Your functions should look like:

void *thread_echo(void *arg)
{
	char buf[1024];
	int i = 0;
	double tmp;
	Echo echo_service = CORBA_OBJECT_NIL;

	echo_service = CORBA_ORB_string_to_object (global_orb, echo_ior, ev);

	for (i=0; i<10000; ++i) {
		printf("Thread %d\n", i);
		snprintf(buf, 1024, "Thread %d\n", i++);
		Echo_echoString(echo_service, buf, &tmp, ev);
	}

	CORBA_Object_release (echo_service, ev);
	return NULL;
}

static void
client_run (CORBA_Environment        *ev)
{
	char buf[1024];
	int i = 0;
	double tmp;
	pthread_t thread;
        Echo echo_service = CORBA_OBJECT_NIL;

	pthread_create(&thread, NULL, thread_echo, NULL);

	echo_service = CORBA_ORB_string_to_object (global_orb, echo_ior, ev);

	for (i=0; i<10000; ++i) {
		printf("Hello %d\n", i);
		snprintf(buf, 1024, "Hello %d\n", i++);

		Echo_echoString(echo_service, buf, &tmp, ev);
	}

	CORBA_Object_release (echo_service, ev);
	printf("Hit any key to quit\n");
	getchar();
}

							Shmyrev.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]