[Gc] Problem with thread registration

Juan Jose Garcia-Ripoll juanjose.garciaripoll at gmail.com
Tue Oct 16 15:53:34 PDT 2012


I have an application that links with ECL which itself uses the garbage
collector. The application creates its own threads, which are _not_ created
using the GC routines. Each thread is then registered with ECL which itself
uses the garbage collector routines to register the thread. However, for
some reason, this does not work well: when the registered thread tries to
allocate memory, it breaks in the garbage collector (though all structures
in the GC have been properly allocated, it seems that GC_init() did not
initialize the part associated with threads).

Any clues? The code for thread registration we use is

switch (GC_register_my_thread((void*)&some_local_variable)) {
 case GC_SUCCESS:
registered = 1;
break;
 case GC_DUPLICATE:
/* Thread was probably created using the GC hooks
 * for thread creation */
 registered = 0;
break;
default:
 return 0;
}

This is a backtrace

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000101a06000
[Switching to process 53103]
GC_push_all_eager (bottom=0x0, top=0x3 <Address 0x3 out of bounds>) at
/Users/jjgarcia/devel/bdwgc.git/mark.c:1524
1524        q = *p;
(gdb) bt
#0  GC_push_all_eager (bottom=0x0, top=0x3 <Address 0x3 out of bounds>) at
/Users/jjgarcia/devel/bdwgc.git/mark.c:1524
#1  0x0000000100340a58 in GC_push_all_stacks () at
/Users/jjgarcia/devel/bdwgc.git/darwin_stop_world.c:316
#2  0x0000000100337f1e in GC_mark_some (cold_gc_frame=0x100fc5928 "\001")
at /Users/jjgarcia/devel/bdwgc.git/mark.c:432
#3  0x000000010032ed2d in GC_stopped_mark (stop_func=0x10032df70
<GC_never_stop_func>) at /Users/jjgarcia/devel/bdwgc.git/alloc.c:645
#4  0x000000010032f2e4 in GC_try_to_collect_inner (stop_func=0x10032df70
<GC_never_stop_func>) at /Users/jjgarcia/devel/bdwgc.git/alloc.c:461
#5  0x000000010032f553 in GC_collect_or_expand (needed_blocks=1097,
ignore_off_page=1, retry=0) at /Users/jjgarcia/devel/bdwgc.git/alloc.c:1266
#6  0x0000000100334843 in GC_alloc_large (lb=4491264, k=0, flags=1) at
/Users/jjgarcia/devel/bdwgc.git/malloc.c:63
#7  0x0000000100335b9e in GC_generic_malloc_ignore_off_page (lb=4491264,
k=0) at /Users/jjgarcia/devel/bdwgc.git/mallocx.c:193
#8  0x00000001001483e9 in ecl_alloc_atomic (n=4491264) at alloc_2.d:736
#9  0x00000001000e3ee1 in ecl_stack_set_size (env=0x1003fb000,
tentative_new_size=<value temporarily unavailable, due to optimizations>)
at interpreter.d:42
#10 0x0000000100004d38 in ecl_init_env (env=0x1003fb000) at main.d:146
#11 0x0000000100144580 in ecl_import_current_thread (name=0x1,
bindings=<value temporarily unavailable, due to optimizations>) at
process.d:393
#12 0x0000000100000ce3 in foo ()
#13 0x00007fff821c3fd6 in _pthread_start ()
#14 0x00007fff821c3e89 in thread_start ()
(gdb) up 11
#11 0x0000000100144580 in ecl_import_current_thread (name=0x1,
bindings=<value temporarily unavailable, due to optimizations>) at
process.d:393
393 ecl_init_env(env);
(gdb) info threads
  9                         0x00007fff8218adc2 in
semaphore_wait_signal_trap ()
  8                         0x00007fff8218adc2 in
semaphore_wait_signal_trap ()
* 7                         GC_push_all_eager (bottom=0x0, top=0x3 <Address
0x3 out of bounds>) at /Users/jjgarcia/devel/bdwgc.git/mark.c:1524
  6                         0x00007fff8218adc2 in
semaphore_wait_signal_trap ()
  5                         0x00007fff82195466 in read ()
  4                         0x00007fff821c5a6a in __semwait_signal ()
  3                         0x00007fff821c5a6a in __semwait_signal ()
  2                         0x00007fff821c5a6a in __semwait_signal ()
  1 "com.apple.main-thread" 0x00007fff821c5a6a in __semwait_signal ()
(gdb) thread 4
[Switching to thread 4 (process 53103)]
0x00007fff821c5a6a in __semwait_signal ()
(gdb) bt 10
#0  0x00007fff821c5a6a in __semwait_signal ()
#1  0x00007fff821c9881 in _pthread_cond_wait ()
#2  0x000000010033ed87 in GC_wait_marker () at
/Users/jjgarcia/devel/bdwgc.git/pthread_support.c:1992
#3  0x0000000100337b6a in GC_help_marker (my_mark_no=4) at
/Users/jjgarcia/devel/bdwgc.git/mark.c:1178
#4  0x00000001003400dc in GC_mark_thread (id=<value temporarily
unavailable, due to optimizations>) at
/Users/jjgarcia/devel/bdwgc.git/pthread_support.c:387
#5  0x00007fff821c3fd6 in _pthread_start ()
#6  0x00007fff821c3e89 in thread_start ()
(gdb) thread 3
[Switching to thread 3 (process 53103)]
0x00007fff821c5a6a in __semwait_signal ()
(gdb) bt
#0  0x00007fff821c5a6a in __semwait_signal ()
#1  0x00007fff821c9881 in _pthread_cond_wait ()
#2  0x000000010033ed87 in GC_wait_marker () at
/Users/jjgarcia/devel/bdwgc.git/pthread_support.c:1992
#3  0x0000000100337b6a in GC_help_marker (my_mark_no=4) at
/Users/jjgarcia/devel/bdwgc.git/mark.c:1178
#4  0x00000001003400dc in GC_mark_thread (id=<value temporarily
unavailable, due to optimizations>) at
/Users/jjgarcia/devel/bdwgc.git/pthread_support.c:387
#5  0x00007fff821c3fd6 in _pthread_start ()
#6  0x00007fff821c3e89 in thread_start ()
(gdb) thread 2
[Switching to thread 2 (process 53103)]
0x00007fff821c5a6a in __semwait_signal ()
(gdb) bt
#0  0x00007fff821c5a6a in __semwait_signal ()
#1  0x00007fff821c9881 in _pthread_cond_wait ()
#2  0x000000010033ed87 in GC_wait_marker () at
/Users/jjgarcia/devel/bdwgc.git/pthread_support.c:1992
#3  0x0000000100337b6a in GC_help_marker (my_mark_no=4) at
/Users/jjgarcia/devel/bdwgc.git/mark.c:1178
#4  0x00000001003400dc in GC_mark_thread (id=<value temporarily
unavailable, due to optimizations>) at
/Users/jjgarcia/devel/bdwgc.git/pthread_support.c:387
#5  0x00007fff821c3fd6 in _pthread_start ()
#6  0x00007fff821c3e89 in thread_start ()
(gdb) thread 1
[Switching to thread 1 (process 53103), "com.apple.main-thread"]
0x00007fff821c5a6a in __semwait_signal ()
(gdb) bt
#0  0x00007fff821c5a6a in __semwait_signal ()
#1  0x00007fff821ec896 in pthread_join ()
#2  0x0000000100000df1 in my_thread_join ()
#3  0x0000000100000d86 in main ()


-- 
Instituto de Física Fundamental, CSIC
c/ Serrano, 113b, Madrid 28006 (Spain)
http://juanjose.garciaripoll.googlepages.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://napali.hpl.hp.com/pipermail/gc/attachments/20121017/034fb747/attachment.htm


More information about the Gc mailing list