From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andy Wingo Newsgroups: gmane.lisp.guile.bugs,gmane.comp.programming.garbage-collection.boehmgc Subject: further pthread foo Date: Fri, 18 Mar 2011 23:26:30 +0100 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1300487202 7635 80.91.229.12 (18 Mar 2011 22:26:42 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 18 Mar 2011 22:26:42 +0000 (UTC) Cc: bug-guile To: gc@linux.hpl.hp.com Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Fri Mar 18 23:26:37 2011 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Q0i7v-0006ez-Hp for guile-bugs@m.gmane.org; Fri, 18 Mar 2011 23:26:36 +0100 Original-Received: from localhost ([127.0.0.1]:48968 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q0i7v-0002eH-1N for guile-bugs@m.gmane.org; Fri, 18 Mar 2011 18:26:35 -0400 Original-Received: from [140.186.70.92] (port=39828 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q0i7n-0002e7-Bw for bug-guile@gnu.org; Fri, 18 Mar 2011 18:26:30 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q0i7j-00039Y-KQ for bug-guile@gnu.org; Fri, 18 Mar 2011 18:26:27 -0400 Original-Received: from a-pb-sasl-sd.pobox.com ([64.74.157.62]:49380 helo=sasl.smtp.pobox.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q0i7j-00039U-Ck for bug-guile@gnu.org; Fri, 18 Mar 2011 18:26:23 -0400 Original-Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-sd.pobox.com (Postfix) with ESMTP id 3DA8E4C6E; Fri, 18 Mar 2011 18:27:57 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:mime-version:content-type; s=sasl; bh=0 P4ZqjPlOMTf/0kkouUJdMwyLAw=; b=WPC3olvfVOrRDsPvBMC/KU3PqhGiOsRpX qMzXPndCpfBC0H2WMHYlWx276baMeDgosN/S3CNkjUz1F3xvHxpyneTRQaUMFqMU +kHlQ1WnlyozYdrVi7oNNOMtN07N7+nxq8SVnWyKRonHF9ffZ0nlTap2hhC/YxIX N1g5Dqm24s= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:date:message-id:mime-version:content-type; q=dns; s= sasl; b=edeOY+kw6FAQGwwJCE74KInAEFOBTdseyy6eGL2u4nqAmy5P8Zj+BnZh 2r0fc8Pl8PuPiF+KGJQ8Bwf8TUeyor5r1x3u5e6A4xbb6iquyqxPCmRYtdpLHqcV ZbJQG7gL8gDZJ7lyu1zcQEZ55e7O6A0/KIANNaebmsJtXA7TxJo= Original-Received: from a-pb-sasl-sd.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-sd.pobox.com (Postfix) with ESMTP id 2BFEA4C6D; Fri, 18 Mar 2011 18:27:55 -0400 (EDT) Original-Received: from unquote.localdomain (unknown [90.164.198.39]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by a-pb-sasl-sd.pobox.com (Postfix) with ESMTPSA id 622AE4C6C; Fri, 18 Mar 2011 18:27:53 -0400 (EDT) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) X-Pobox-Relay-ID: F82B10F8-51AE-11E0-8567-E8AB60295C12-02397024!a-pb-sasl-sd.pobox.com X-detected-operating-system: by eggs.gnu.org: Solaris 10 (beta) X-Received-From: 64.74.157.62 X-BeenThere: bug-guile@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.bugs:5342 gmane.comp.programming.garbage-collection.boehmgc:4433 Archived-At: Hello again! Continuing on the same topic as my previous mail, which you may read here: http://thread.gmane.org/gmane.lisp.guile.bugs/5340 I modified the program to do a `scm_init_guile ()' before creating any threads. This initializes libgc from the main thread, so all should be well. But then I run into a problem: (gdb) r Starting program: /tmp/many_threads [Thread debugging using libthread_db enabled] 0: create[New Thread 0x7ffff740b700 (LWP 23030)] join Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7ffff740b700 (LWP 23030)] 0x00007ffff7a09200 in GC_malloc (bytes=16) at thread_local_alloc.c:161 161 GC_FAST_MALLOC_GRANS(result, granules, tiny_fl, DIRECT_GRANULES, (gdb) thr apply all bt Thread 2 (Thread 0x7ffff740b700 (LWP 23030)): #0 0x00007ffff7a09200 in GC_malloc (bytes=16) at thread_local_alloc.c:161 #1 0x00007ffff7d1208e in scm_cell (x=, y=) at ../libguile/inline.h:124 #2 scm_cons (x=, y=) at pairs.c:77 #3 0x00007ffff7cd05b7 in scm_i_with_continuation_barrier (body=0x7ffff7cd03a0 , body_data=0x7ffff740adb0, handler=0x7ffff7cd03c0 , handler_data=0x7ffff740adb0, pre_unwind_handler=, pre_unwind_handler_data=) at continuations.c:444 #4 0x00007ffff7cd0690 in scm_c_with_continuation_barrier (func=, data=) at continuations.c:491 #5 0x00007ffff7a0982f in GC_call_with_gc_active (fn=0x7ffff7d48740 , client_data=0x7ffff740ae20) at pthread_support.c:1127 #6 0x00007ffff7d48aed in with_gc_active (func=0x7ffff7d488e0 , data=0x949600, parent=) at threads.c:97 #7 scm_i_with_guile_and_parent (func=0x7ffff7d488e0 , data=0x949600, parent=) at threads.c:826 #8 0x00007ffff7d48bc7 in do_thread_exit_trampoline (sb=, v=0x949600) at threads.c:549 #9 0x00007ffff7a03525 in GC_call_with_stack_base (fn=, arg=) at misc.c:1493 #10 0x00007ffff7d48867 in on_thread_exit (v=0x949600) at threads.c:580 #11 0x0000003fc86077f9 in __nptl_deallocate_tsd (arg=0x7ffff740b700) at pthread_create.c:154 #12 start_thread (arg=0x7ffff740b700) at pthread_create.c:308 #13 0x0000003fc7ee098d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:115 Thread 1 (Thread 0x7ffff76ce700 (LWP 23027)): #0 0x0000003fc8607fbd in pthread_join (threadid=140737341601536, thread_return=0x7fffffffe018) at pthread_join.c:89 #1 0x00007ffff7a09e47 in GC_pthread_join (thread=140737341601536, retval=0x7fffffffe018) at pthread_support.c:1219 #2 0x00000000004008e7 in main () at many_threads.c:31 What is happening is that I have registered a pthread_key cleanup handler, and I need to call a Guile function in that handler. But quite possibly, libgc has already torn down this thread. So I trampoline through a GC_call_with_stack_base, then register the current thread. If that returns GC_SUCCESS, later I unregister it. In between there is the scm_i_with_guile_and_parent call you see at frame #7. However as you see, there is unhappiness there. I don't know what exactly is causing the segfault, but here's a disassembly: (gdb) disassemble $pc Dump of assembler code for function GC_malloc: 0x00007ffff7a09180 <+0>: mov %rbx,-0x30(%rsp) 0x00007ffff7a09185 <+5>: mov %r13,-0x18(%rsp) 0x00007ffff7a0918a <+10>: mov %rdi,%rbx 0x00007ffff7a0918d <+13>: mov %rbp,-0x28(%rsp) 0x00007ffff7a09192 <+18>: mov %r12,-0x20(%rsp) 0x00007ffff7a09197 <+23>: mov %r14,-0x10(%rsp) 0x00007ffff7a0919c <+28>: mov %r15,-0x8(%rsp) 0x00007ffff7a091a1 <+33>: sub $0x48,%rsp 0x00007ffff7a091a5 <+37>: mov 0x20a104(%rip),%rax # 0x7ffff7c132b0 0x00007ffff7a091ac <+44>: mov (%rax),%r12d 0x00007ffff7a091af <+47>: data32 lea 0x20a3e9(%rip),%rdi # 0x7ffff7c135a0 0x00007ffff7a091b7 <+55>: data32 data32 callq 0x7ffff79f6da0 <__tls_get_addr@plt> 0x00007ffff7a091bf <+63>: mov (%rax),%r13 0x00007ffff7a091c2 <+66>: test %r13,%r13 0x00007ffff7a091c5 <+69>: je 0x7ffff7a0923f 0x00007ffff7a091c7 <+71>: add $0xf,%r12d 0x00007ffff7a091cb <+75>: movslq %r12d,%r12 0x00007ffff7a091ce <+78>: lea (%rbx,%r12,1),%r12 0x00007ffff7a091d2 <+82>: shr $0x4,%r12 0x00007ffff7a091d6 <+86>: cmp $0x18,%r12 0x00007ffff7a091da <+90>: ja 0x7ffff7a0923f 0x00007ffff7a091dc <+92>: lea 0x18(%r12),%r14 0x00007ffff7a091e1 <+97>: mov %r12,%rbp 0x00007ffff7a091e4 <+100>: mov $0x10,%r15d 0x00007ffff7a091ea <+106>: shl $0x4,%rbp 0x00007ffff7a091ee <+110>: mov 0x8(%r13,%r14,8),%rax 0x00007ffff7a091f3 <+115>: lea 0x8(%r13,%r14,8),%rcx 0x00007ffff7a091f8 <+120>: cmp $0x11a,%rax 0x00007ffff7a091fe <+126>: jbe 0x7ffff7a09269 => 0x00007ffff7a09200 <+128>: mov (%rax),%rdx 0x00007ffff7a09203 <+131>: mov %rdx,0x8(%r13,%r14,8) 0x00007ffff7a09208 <+136>: prefetcht0 (%rdx) 0x00007ffff7a0920b <+139>: movq $0x0,(%rax) 0x00007ffff7a09212 <+146>: mov 0x18(%rsp),%rbx 0x00007ffff7a09217 <+151>: mov 0x20(%rsp),%rbp 0x00007ffff7a0921c <+156>: mov 0x28(%rsp),%r12 0x00007ffff7a09221 <+161>: mov 0x30(%rsp),%r13 0x00007ffff7a09226 <+166>: mov 0x38(%rsp),%r14 0x00007ffff7a0922b <+171>: mov 0x40(%rsp),%r15 0x00007ffff7a09230 <+176>: add $0x48,%rsp 0x00007ffff7a09234 <+180>: retq (gdb) info registers rax 0x1000 4096 rbx 0x10 16 rcx 0x6b1650 7018064 rdx 0x2 2 rsi 0x0 0 rdi 0x6027e0 6301664 rbp 0x10 0x10 rsp 0x7ffff740acc0 0x7ffff740acc0 r8 0x7ffff7d490b0 140737351291056 r9 0x0 0 r10 0x7ffff740aba0 140737341598624 r11 0x7ffff7a097c0 140737347884992 r12 0x1 1 r13 0x6b1580 7017856 r14 0x19 25 r15 0x10 16 rip 0x7ffff7a09200 0x7ffff7a09200 eflags 0x10212 [ AF IF RF ] cs 0x33 51 ss 0x2b 43 ds 0x0 0 es 0x0 0 fs 0x0 0 gs 0x0 0 This is with current CVS. Regards, Andy -- http://wingolog.org/