RE: graceful mulit-threaded shutdown



Thanks, I think the problem was that I was not properly disposing of the
servant.  I have a feeling that it is now  correctly destroying it, but when
it comes to destroying the orb, I still get the 

** ERROR ** Must shutdown ORB from main thread error.

the shutdown is being called during the destroy call on the orb.

my set up/tear down is:

linc_set_threaded(TRUE);
(*orb) = CORBA_ORB_init(argc_ptr, argv, "orbit-local-mt-orb", ev);

poa = (PortableServer_POA) CORBA_ORB_resolve_initial_references(orb,
"RootPOA", ev);

/* set thread hint */
ORBit_ObjectAdaptor_set_thread_hint(poa, ORBIT_THREAD_HINT_PER_REQUEST);

/* activate POA Manager */
poa_manager = PortableServer_POA__get_the_POAManager(poa, ev);
PortableServer_POAManager_activate(poa_manager, ev);
CORBA_Object_release((CORBA_Object)poa_manager,ev);

/* create servant in context of poa container */
servant = impl_c2dMessage__create (poa, ev);

GMainContext *ctxt;
ctxt = g_main_context_default ();
global_loop = g_main_loop_new (ctxt, TRUE);
/******RUN*********/
g_main_loop_run (global_loop);
/******DONE RUNNING****/

/* Shutdown servant */
c2dMessage_servant = PortableServer_POA_reference_to_servant(poa, servant
,&global_env);
CORBA_Object_release(servant ,&global_env);
impl_c2dMessage__destroy(c2dMessage_servant,&global_env);

// Shutdown 'poa'
CORBA_Object_release((CORBA_Object)poa,&global_env);

// Shutdown 'orb' 
CORBA_ORB_destroy(global_orb,&global_env);

This is essentially what you've been doing, with the multithreaded orb added
into the mix.  The shutdown sequence takes place immediately after the call
to run.  I've tried moving this to a call made by the parent thread that
creates my orb's thread with the same result (although it doesn't really
make sense to do so).

I've tried electric fence, but the machine I'm debugging on is vastly
underpowered will basically refuse to debug this way (or perhaps I'm not
doing something right, but I've I heard efence sucks the memory and cycles
up like crazy).  I wish i had a better machine!

again, the backtrace is:

(gdb) bt
#0  0x42028851 in kill () from /lib/i686/libc.so.6
#1  0x402adf4d in raise () from /lib/i686/libpthread.so.0
#2  0x420284f4 in raise () from /lib/i686/libc.so.6
#3  0x42029beb in abort () from /lib/i686/libc.so.6
#4  0x40257f38 in g_logv () from /usr/lib/libglib-2.0.so.0
#5  0x40257f74 in g_log () from /usr/lib/libglib-2.0.so.0
#6  0x401b8724 in giop_shutdown () from /usr/lib/libORBit-2.so.0
#7  0x401bd04b in CORBA_ORB_shutdown () from /usr/lib/libORBit-2.so.0
#8  0x401bd0f9 in CORBA_ORB_destroy () from /usr/lib/libORBit-2.so.0
#9  0x401bbab1 in ORBit_ORB_start_servers () from /usr/lib/libORBit-2.so.0

I'm still diggin in to figure out why it doesn't seem to like the thread it
is in.  This doesn't make much sense to me.

-Tyler

-----Original Message-----
From: Jan Kratochvil [mailto:lace@jankratochvil.net]
Sent: Monday, November 10, 2003 12:08 PM
To: Tyler Kohn
Cc: 'orbit-list@gnome.org'
Subject: Re: graceful mulit-threaded shutdown


Hi,

On Mon, 10 Nov 2003 17:48:03 +0100, Tyler Kohn wrote:
> 
> Thanks, I went ahead and did this and it works great for getting me out of
> the running thread, but I still am getting a seg fault.

BTW I recommend
	LD_PRELOAD=/usr/lib/libefence.so

as otherwise the point of failure may be misleading.


> When it finally
> crashed during shutdown, the backtrace is:
> 
> #0  0x401ce23f in ORBit_POA_setup_root () from /usr/lib/libORBit-2.so.0
> #1  0xbffff690 in ?? ()
> #2  0x401cd219 in ORBit_POA_is_inuse () from /usr/lib/libORBit-2.so.0
> #3  0x40246ee6 in g_hash_table_foreach () from /usr/lib/libglib-2.0.so.0
> #4  0x401cd317 in ORBit_POA_deactivate () from /usr/lib/libORBit-2.so.0
> #5  0x401cd081 in ORBit_POA_is_inuse () from /usr/lib/libORBit-2.so.0
> #6  0x401cfd24 in PortableServer_POA_destroy () from
> /usr/lib/libORBit-2.so.0
> #7  0x401bd03f in CORBA_ORB_shutdown () from /usr/lib/libORBit-2.so.0
> #8  0x401bd0f9 in CORBA_ORB_destroy () from /usr/lib/libORBit-2.so.0
> #9  0x401bbab1 in ORBit_ORB_start_servers () from /usr/lib/libORBit-2.so.0
> #10 0x4202ac92 in exit () from /lib/i686/libc.so.6
> #11 0x420158ff in __libc_start_main () from /lib/i686/libc.so.6
> (gdb)
> 
> the poa doesn't seem to want to shutdown due to remaining refrence.
during
> the lifecycle of my app I create the orb, a server, and a client.  On
> shutdown I clean up the client first:
> 	CORBA_Object_release(client, ev);
> I don't release the orb yet since the server still is around.
> 
> I then call 
> 	g_main_loop_quit(loop);

Beware: I do not use Naming service, I depend on direct IOR references.
Complete sequence I use with clean referencing and shutdown:

	/* Init 'orb' */
	/* libcaptive is single-threaded only, caller must lock it.
	 * If thread A spawned the sandbox while currently doing its own
work
	 * and thread B calls the sandbox thread B waits on ORB_run()
	 * while the sandbox waits for the response of thread A ORB.
Deadlock.
	 * "orbit-local-non-threaded-orb" requests thread unaware ORB.
	 */
	
*orbp=CORBA_ORB_init(&orb_argc,orb_argv,"orbit-local-non-threaded-orb",evp);
	/* Init 'poa' */
	
*poap=(PortableServer_POA)CORBA_ORB_resolve_initial_references(*orbp,"RootPO
A",evp);
	{
	PortableServer_POAManager poa_mgr;
		poa_mgr=PortableServer_POA__get_the_POAManager(*poap,evp);
		PortableServer_POAManager_activate(poa_mgr,evp);
		CORBA_Object_release((CORBA_Object)poa_mgr,evp);
	}
	/* Init 'Vfs_object' */
	
Vfs_object=impl_Captive_Vfs__create(captive_corba_poa,&captive_corba_ev);
	/* Pass IOR to our parent. */
	
Vfs_IOR=CORBA_ORB_object_to_string(captive_corba_orb,Vfs_object,&captive_cor
ba_ev);
	printf("ior=%s\n",Vfs_IOR);

	g_main_loop_run(captive_corba_get_loop());

	/* Shutdown 'Vfs' servant */
	
Vfs_servant=PortableServer_POA_reference_to_servant(captive_corba_poa,Vfs_ob
ject,&captive_corba_ev);
	CORBA_Object_release(Vfs_object,&captive_corba_ev);
	impl_Captive_Vfs__destroy(Vfs_servant,&captive_corba_ev);
	/* Shutdown 'poa' */
	CORBA_Object_release((CORBA_Object)poa,evp);
	/* Shutdown 'orb' */
	CORBA_ORB_destroy(orb,evp);


I am not aware of current inter-thread issues of ORBit-2.7.x+, it is valid
for
me to use:
	
CORBA_ORB_init(&orb_argc,orb_argv,"orbit-local-non-threaded-orb",evp);

If you need just to call g_main_loop_quit() from a 'different thread' while
no
other ORBit features need to be used by 'different threads' I can recommend
it
to simplify it all. Michael Meeks may curse me.


> In my "run" method, after g_main_loop_run (loop) returns I call:
>     CORBA_Object_release(servant, ev);
> if that doesn't raise an exception (it doesn't appear to) and if the orb
is
> not null, I call:
>         CORBA_ORB_destroy (orb, ev);

The servant itself remains running as its impl_*__destroy() was not called.
Also POA remains alive.



Regards,
Lace

-- 
Jan Kratochvil; Captive: free r/w NTFS Filesystem;
http://www.jankratochvil.net/



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