Re: threading woes



Great work Bowie. I shall give it a go later this (UK) afternoon.

Nick


Bowie Owens wrote:

Bowie Owens wrote:

Hi,

I received a request for some help on the orbitcpp-list. It relates to using threading as part of the implementation of a servant (but not using POA threading policies). The IDL looks kind of like this:

module test {
       interface Worker {
               void ping ();
       };

       interface Master {
               void create_thread ();
               void submit_work (in Worker server);
       };
};

The Master servant in creates a new thread using glib in the create_thread() method. It the receives a reference to a Worker servant (in a different process) from the submit_work() method. The master then calls the ping() method on the Worker object. If the ping() is called in the same thread as the main loop, everythings works fine. However, if the ping() is called from the thread created in create_thread() the ORB drops out of its main loop and things fall apart. I've attached a log of ORBIT2_DEBUG=all. For the adventurous this is checked in to CVS under orbitcpp/test/cpp/threading. I was wondering if anyone had any insight into why the ORB is dropping out of its run loop or how I can find out why.


I've just worked it out myself. The program is using the linc_loop and the g_main_loop_quit (link_loop) is happening within link_exec_set_io_thread() which is getting called indirectly from giop_thread_new_check() (see backtrace below). I needed to ensure that link_set_io_thread(TRUE) is called before the run loop is entered. Nick, this can be achieved by using the passing orb identifier "orbit-io-thread" to CORBA::ORB_init(). However, I think this is bug since it seems like the intention is that we can switch transparently from non-threaded io to threaded io. I've attached a patch which causes giop_main_run() to enter the giop_main_loop after we quit the link_loop if giop_thread_io() has become true.

#0 link_exec_set_io_thread (data=0xbf7ff8c4, immediate=1) at linc.c:379
#1 0x4007b2a7 in link_dispatch_command (data=0xbf7ff8c4, immediate=1)
at linc.c:447
#2 0x4007aac6 in link_exec_command (cmd=0xbf7ff8c4) at linc.c:115
#3 0x4007b22f in link_set_io_thread (io_in_thread=1) at linc.c:432
#4 0x4005493f in giop_thread_new_check (opt_self=0x80646c8) at giop.c:826
#5 0x4005c018 in ORBit_small_invoke_stub (obj=0x80671c0, m_data=0x8056800,
ret=0x0, args=0x0, ctx=0x0, ev=0xbf7ffa3c) at orbit-small.c:629
#6 0x4005be7c in ORBit_small_invoke_stub_n (object=0x80671c0,
methods=0x8056864, index=0, ret=0x0, args=0x0, ctx=0x0, ev=0xbf7ffa3c)
at orbit-small.c:575
#7 0x400745e9 in ORBit_c_stub_invoke (obj=0x80671c0, methods=0x8056864,
method_index=0, ret=0x0, args=0x0, ctx=0x0, ev=0xbf7ffa3c, class_id=1,
method_offset=4, skel_impl=0x80531a4 <_ORBIT_skel_small_test_Worker_ping>)
at poa.c:2640
#8 0x08054642 in test_Worker_ping ()
#9 0x080532f6 in test::Worker::ping() ()
#10 0x08050c7f in server_thread::consumer() ()
#11 0x08050afd in server_thread::thread_consumer(void*) ()
#12 0x401931f4 in g_thread_create_proxy ()
from /local_scratch/owe043/opt/gnome2/lib/libglib-2.0.so.0
#13 0x400ffc0e in pthread_start_thread_event () from /lib/libpthread.so.0


------------------------------------------------------------------------

Index: ./src/orb/GIOP/giop.c
===================================================================
RCS file: /cvs/gnome/ORBit2/src/orb/GIOP/giop.c,v
retrieving revision 1.50
diff -u -p -r1.50 giop.c
--- ./src/orb/GIOP/giop.c 4 Mar 2004 17:49:37 -0000 1.50
+++ ./src/orb/GIOP/giop.c 21 Dec 2004 01:06:54 -0000
@@ -597,6 +597,9 @@ static GMainLoop *giop_main_loop = NULL;
void
giop_main_run (void)
{
+ if (!giop_thread_io ())
+ link_main_loop_run ();
+
if (giop_thread_io ()) {
g_assert (giop_thread_self () == giop_main_thread);
g_assert (giop_main_loop == NULL);
@@ -604,8 +607,7 @@ giop_main_run (void)
g_main_loop_run (giop_main_loop);
g_main_loop_unref (giop_main_loop);
giop_main_loop = NULL;
- } else
- link_main_loop_run ();
+ } }


void





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