Re: ORBit2.8.3 thread problem
- From: Kuang-Chun Cheng <kccheng openate com>
- To: Shmyrev <nshmyrev yandex ru>, gnome-devel-list gnome org
- Cc:
- Subject: Re: ORBit2.8.3 thread problem
- Date: Mon, 06 Sep 2004 13:43:46 +0800
Hi,
Sorry for my last un-clear question. I modify the echo-client.c (comes from
"ORBit beginners Documentation v1.6") and repeat my problem below.
* add "#include <linc/linc.h>" and "#include <pthread.h>"
* add "linc_set_threaded(TRUE)" before CORBA_ORB_init().
* change "orbit-local-orb" to "orbit-local-mt-orb".
* rewrite client_run() as following:
static void
client_run (Echo echo_service,
CORBA_Environment *ev)
{
char buf[1024];
int i = 0;
pthread_t thread;
pthread_create(&thread, NULL, thread_echo, NULL); // create a thread here
for (i=0; i<20000; ++i) { // this will stop when i == 8192 !!!!!!!
printf("Hello %d\n", i);
snprintf(buf, 1024, "Hello %d\n", i++);
Echo_echoString(echo_service, buf, ev);
if (etk_raised_exception (ev)) return;
}
printf("Hit any key to quit\n");
getchar();
}
* create thread_echo() as
void *thread_echo(void *arg)
{
char buf[1024];
int i = 0;
for (i=0; i<20000; ++i) {
printf("Thread %d\n", i);
snprintf(buf, 1024, "Thread %d\n", i++);
Echo_echoString(echo_service, buf, ev);
if (etk_raised_exception (ev)) return;
}
return NULL;
}
* basically, what I did is create a thread. Inside both child thread and
main thread,
I call Echo_echoString() in a loop.
If I comment out the pthread_create(), I can run the client without any
problem.
If the pthread_create() existed, then I can only run the
Echo_echoString() 8192 times
and the main thread hang up.
Could someone tell me what's wrong here ? What's the correct procedure
to invoke
CORBA method (eg Echo_echoString()) from a thread ?
Do I need to change anything in server side ??
Thanks.
Kuang-Chun Cheng
kccheng openate com
Shmyrev wrote:
>В сообщении от 27 Август 2004 22:18 Kuang-Chun Cheng написал(a):
>
>It seems that it is threads limit in your kernel. On every call new thread is
>started. You can see all those threads by examining 'ps' command output
>(probably, you'll need some options).
>
>Your description of the problem is rather unclear, it seems that only few
>people can understand them. Anyway, if you can send me small complete
>example, we can solve your problem. Or provide a link, where we can download
>it. Example is always better.
>
> Shmyrev
>
>
>
>>Hi,
>>
>>Could you tell me how ? Or where should I looking for the answer ?
>>Thanks.
>>
>>Regards
>>Kuang-Chun Cheng
>>kccheng openate com
>>
>>Colin Walters wrote:
>>
>>
>>>On Fri, 2004-08-27 at 11:08 +0800, Kuang-Chun Cheng wrote:
>>>
>>>
>>>>Hi,
>>>>
>>>>I run the EchoString example by calling EchoString inside a thread.
>>>>It works OK if I always call CORBA related command inside thread.
>>>>However, if I enable thread and call EchoString or any CORBA related
>>>>command from main thread ... after 4096 calls, the CORBA command
>>>>will just hang there.
>>>>
>>>>Where is the 4096 limitation comes from ?
>>>>
>>>>
>>>That's the trial limit; you need to send a request to your object broker
>>>to purchase more messages.
>>>
>>>
>>_______________________________________________
>>gnome-devel-list mailing list
>>gnome-devel-list gnome org
>>http://mail.gnome.org/mailman/listinfo/gnome-devel-list
>>
>>
#include <stdio.h>
#include <signal.h>
#include <pthread.h>
#include <orbit/orbit.h>
#include <linc/linc.h>
#include "echo.h"
Echo echo_service = CORBA_OBJECT_NIL;
CORBA_Environment ev[1];
static CORBA_ORB global_orb = CORBA_OBJECT_NIL; /* global orb */
static void
client_shutdown (int sig)
{
CORBA_Environment local_ev[1];
CORBA_exception_init(local_ev);
if (global_orb != CORBA_OBJECT_NIL)
{
CORBA_ORB_shutdown (global_orb, FALSE, local_ev);
etk_abort_if_exception (local_ev, "caught exception");
}
}
static void
client_init (int *argc_ptr,
char *argv[],
CORBA_ORB *orb,
CORBA_Environment *ev)
{
/* init signal handling */
signal(SIGINT, client_shutdown);
signal(SIGQUIT, client_shutdown);
signal(SIGTERM, client_shutdown);
/* create Object Request Broker (ORB) */
(*orb) = CORBA_ORB_init(argc_ptr, argv, "orbit-local-mt-orb", ev);
if (etk_raised_exception(ev)) return;
}
static void
client_cleanup (CORBA_ORB orb,
CORBA_Object service,
CORBA_Environment *ev)
{
/* releasing managed object */
CORBA_Object_release(service, ev);
if (etk_raised_exception(ev)) return;
/* tear down the ORB */
if (orb != CORBA_OBJECT_NIL)
{
/* going to destroy orb.. */
CORBA_ORB_destroy(orb, ev);
if (etk_raised_exception(ev)) return;
}
}
void *thread_echo(void *arg)
{
char buf[1024];
int i = 0;
for (i=0; i<20000; ++i) {
printf("Thread %d\n", i);
snprintf(buf, 1024, "Thread %d\n", i++);
Echo_echoString(echo_service, buf, ev);
if (etk_raised_exception (ev)) return;
}
return NULL;
}
static void
client_run (Echo echo_service,
CORBA_Environment *ev)
{
char buf[1024];
int i = 0;
pthread_t thread;
pthread_create(&thread, NULL, thread_echo, NULL);
for (i=0; i<20000; ++i) {
printf("Hello %d\n", i);
snprintf(buf, 1024, "Hello %d\n", i++);
Echo_echoString(echo_service, buf, ev);
if (etk_raised_exception (ev)) return;
}
printf("Hit any key to quit\n");
getchar();
}
int main (int argc, char* argv[])
{
CORBA_char filename[] = "echo.ref";
CORBA_exception_init(ev);
linc_set_threaded(TRUE);
client_init (&argc, argv, &global_orb, ev);
etk_abort_if_exception(ev, "init failed");
g_print ("Reading service reference from file \"%s\"\n", filename);
echo_service = (Echo) etk_import_object_from_file (global_orb,
filename,
ev);
etk_abort_if_exception(ev, "import service failed");
client_run (echo_service, ev);
etk_abort_if_exception(ev, "service not reachable");
client_cleanup (global_orb, echo_service, ev);
etk_abort_if_exception(ev, "cleanup failed");
exit (0);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]