I am working on a project that mixes native code with the CLI, and I am
having problems with threading.  The problems arise because the native
code creates its own threads, and those threads can call into the CLI
universe.  To handle this, I have code that bridges between the native
code and the CLI, and in places where a thread spawned by the native
code will call into the CLI universe, mono_thread_attach() is called
first.  Unfortunately, this does not seem to be sufficient.

What I am seeing is that my code can run for a few seconds, but then it
crashes consistently at the end of the Boehm GC function
pthread_push_all_stacks().  The full stack trace of the crash is
attached.  (Note that I am using Mono 0.97 on Fedora Core 1 with the
Boehm GC code that comes bundled with the Mono runtime source.)  The
crash appears to occur because Boehm GC does not know about at least one
of the threads created by the aforementioned native code.

I cannot modify the native code to use GC_pthread_create() and friends,
so I am trying to find a way to let Boehm GC know about the threads
created by the native code.  I have done a little bit of digging, and I
see that Boehm GC can use the function call wrapping feature of GNU ld. 
However, I do not see anything in the Mono build process that enables or
takes advantage of this feature.

I am prepared to take steps to try out this capability of Boehm GC and
GNU ld, but before I do, I am curious to know if there is something in
Mono's API that I can call to register externally created threads with
the garbage collector.  mono_thread_attach() by itself does not appear
to be quite enough for my case, but I may be missing something.  Is
there another Mono API call I can make or some Boehm GC thread
registration call?  If not, I will go ahead with the function call
wrapping via ld in hopes of getting my code to work.

 -Patrick


-- 
Patrick L. Hartling                     | Research Assistant, VRAC
http://www.137.org/patrick/             | 2274 Howe Hall Room 2624
PGP: http://tinyurl.com/ywd54           | http://www.vrac.iastate.edu/
#0  0x0031ac32 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
#1  0x00840989 in raise () from /lib/tls/libc.so.6
#2  0x00842342 in abort () from /lib/tls/libc.so.6
#3  0x00d85467 in GC_abort (msg=0xdd2fe0 "Collecting from unknown thread.")
    at misc.c:1071
#4  0x00d8a467 in pthread_push_all_stacks () at pthread_stop_world.c:270
#5  0x00d8a4fc in GC_push_all_stacks () at pthread_stop_world.c:277
#6  0x00d863d6 in GC_default_push_other_roots () at os_dep.c:2048
#7  0x00d846ee in GC_push_roots (all=1, cold_gc_frame=0x48e31f8 "\034¿?¿?")
    at mark_rts.c:648
#8  0x00d82592 in GC_mark_some (cold_gc_frame=0x48e31f8 "\034¿?¿?") at mark.c:304
#9  0x00d7c896 in GC_stopped_mark (stop_func=0xd7c11c <GC_never_stop_func>)
    at alloc.c:520
#10 0x00d7c562 in GC_try_to_collect_inner (
    stop_func=0xd7c11c <GC_never_stop_func>) at alloc.c:367
#11 0x00d7d2c8 in GC_collect_or_expand (needed_blocks=1, ignore_off_page=0)
    at alloc.c:998
#12 0x00d7d4ba in GC_allocobj (sz=28, kind=1) at alloc.c:1073
#13 0x00d810be in GC_generic_malloc_inner (lb=112, k=1) at malloc.c:136
#14 0x00d811bb in GC_generic_malloc (lb=112, k=1) at malloc.c:192
#15 0x00d8145d in GC_malloc (lb=112) at malloc.c:297
#16 0x00d1be8f in mono_array_new_full (domain=0x9617980,
    array_class=0x99b4a38, lengths=0x98714c8, lower_bounds=0x0)
    at object.c:1659
#17 0x00cc534d in mono_array_new_va (cm=0x99b4a00) at jit-icalls.c:420
#18 0x0067908e in ?? ()
#19 0x099b4a00 in ?? ()
#20 0x00000006 in ?? ()
#21 0x00000004 in ?? ()
#22 0x3f7c1c5c in ?? ()
#23 0x0039d8c8 in __JCR_LIST__ ()
   from 
/home/users/patrick/src/Juggler/main/juggler/build.linux-fc1.posix.gcc33/instlinks/lib/i686/libvrj.so
#24 0x048e33e8 in ?? ()
#25 0x00355c54 in __normal_iterator (this=0x9685f80, [EMAIL PROTECTED])
    at stl_iterator.h:593
#26 0x00531a14 in ?? ()
#27 0x09685f80 in ?? ()

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to