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 Subject: bug#19523: Segfault when creating thread with scm_with_guile Date: Wed, 22 Jun 2016 23:27:34 +0200 Message-ID: <87k2hgrk1l.fsf@pobox.com> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1466630907 31683 80.91.229.3 (22 Jun 2016 21:28:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 22 Jun 2016 21:28:27 +0000 (UTC) Cc: 19523@debbugs.gnu.org To: Anthonin Bonnefoy Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Wed Jun 22 23:28:17 2016 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1bFph2-0002II-6p for guile-bugs@m.gmane.org; Wed, 22 Jun 2016 23:28:16 +0200 Original-Received: from localhost ([::1]:60976 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFph1-0007Mk-C8 for guile-bugs@m.gmane.org; Wed, 22 Jun 2016 17:28:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49740) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFpgt-0007EZ-3Q for bug-guile@gnu.org; Wed, 22 Jun 2016 17:28:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bFpgo-0003DO-Iy for bug-guile@gnu.org; Wed, 22 Jun 2016 17:28:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:39228) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFpgo-0003DK-EW for bug-guile@gnu.org; Wed, 22 Jun 2016 17:28:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bFpgo-0007aQ-AA for bug-guile@gnu.org; Wed, 22 Jun 2016 17:28:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Andy Wingo Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Wed, 22 Jun 2016 21:28:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 19523 X-GNU-PR-Package: guile X-GNU-PR-Keywords: Original-Received: via spool by 19523-submit@debbugs.gnu.org id=B19523.146663086729133 (code B ref 19523); Wed, 22 Jun 2016 21:28:02 +0000 Original-Received: (at 19523) by debbugs.gnu.org; 22 Jun 2016 21:27:47 +0000 Original-Received: from localhost ([127.0.0.1]:51563 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bFpgY-0007Zj-Px for submit@debbugs.gnu.org; Wed, 22 Jun 2016 17:27:47 -0400 Original-Received: from pb-sasl1.pobox.com ([64.147.108.66]:50188 helo=sasl.smtp.pobox.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bFpgX-0007ZY-5r for 19523@debbugs.gnu.org; Wed, 22 Jun 2016 17:27:45 -0400 Original-Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-sasl1.pobox.com (Postfix) with ESMTP id 6B4242360C; Wed, 22 Jun 2016 17:27:43 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=sXdl6JXvzV7dkeMoXl1PiqJpspI=; b=M0NVwq 7F7ky2b7zYXgY+kP/4zzIh3ztHwnFqgc2K2MV42rGPMvq8xrn+BS4CCj72mHdkwa M0jL5ooZVzokIPXY3qTRcHT7vdLUwzsuIQnI6cOVGtCCKblta0BXpHb9WrqoHQ5u 69k/tujHIjzNV1P31Y4OEOOvc0AV6q/GbL+VA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=sasl; b=PErV19dOytLvyAs/H5+g279+Lc7Gz1qP CoZtNvOD5gzRT6VRc38m4pfnz7tqgBUpawYO8IRvfsMdIGOYUMiAJrR+mVcQ7DUQ 0vUmLfd4wRO5r94PqGnN4eDkwpLU5fKvxLm+wDuKnOjnHLvL26PA6MFKJRRF7KPr p0aNddPuXi0= Original-Received: from pb-sasl1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-sasl1.pobox.com (Postfix) with ESMTP id 635FB2360B; Wed, 22 Jun 2016 17:27:43 -0400 (EDT) Original-Received: from clucks (unknown [88.160.190.192]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by pb-sasl1.pobox.com (Postfix) with ESMTPSA id 530692360A; Wed, 22 Jun 2016 17:27:42 -0400 (EDT) In-Reply-To: (Anthonin Bonnefoy's message of "Tue, 6 Jan 2015 15:27:31 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) X-Pobox-Relay-ID: 275FC604-38C0-11E6-9C84-C1836462E9F6-02397024!pb-sasl1.pobox.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.org gmane.lisp.guile.bugs:8141 Archived-At: I can reproduce this bug, but I can't get backtraces from my core file :/ Irritating. Are you able to get backtraces reliably? Can you provide a "thr apply all bt" ? Regards, Andy On Tue 06 Jan 2015 15:27, Anthonin Bonnefoy writes: > Hi all, > > I have segfaults occurring sometimes when threads are starting with > scm_with_guile while main thread is using malloc. > > Example program: > ``` > #include > #include > #include > > static void *a_libguile_thread(void *unused) { > } > > static void *a_libguile_thread_(void *unused) { > scm_with_guile(a_libguile_thread, NULL); > } > > static void do_mallocs(void) { > void *a[1000]; > for (int i = 0; i < 1000; ++i) { > a[i] = malloc(356); > } > for (int i = 0; i < 1000; ++i) { > free(a[i]); > } > } > > int main(int argc, char *argv[]) { > scm_init_guile(); > > pthread_t pth[10]; > for (int i = 0; i < 10; ++i) { > GC_pthread_create(pth + i, NULL, a_libguile_thread_, NULL); > } > > do_mallocs(); > > for (int i = 0; i < 10; ++i) { > GC_pthread_join(pth[i], NULL); > } > > return 0; > } > > ``` > To compile: > gcc corruption_guile.c -g -std=c99 `pkg-config --cflags --libs > guile-2.0` > ``` > Some iterations are needed before having the segfaults: > while ./a.out; do echo -n "."; done; > ``` > Versions: > gcc (Debian 4.9.1-19) 4.9.1 > guile (GNU Guile) 2.0.11.20-4338f (also tried from v2.0.11 tag) > libgc gc7_2d > ``` > Backtrace: > > #0 GC_generic_malloc (lb=524288, k=) at malloc.c:185 > #1 0x00007fcc535541ff in make_vm () at vm.c:704 > #2 0x00007fcc535542d5 in scm_the_vm () at vm.c:781 > #3 0x00007fcc534da600 in scm_call_4 (proc=0x1198c30, > arg1=arg1@entry=0x404, arg2=, arg3=, > arg4=) at eval.c:507 > #4 0x00007fcc53550d89 in scm_catch_with_pre_unwind_handler > (key=key@entry=0x404, thunk=, handler=, > pre_unwind_handler=) at throw.c:73 > #5 0x00007fcc53550e8f in scm_c_catch (tag=tag@entry=0x404, > body=body@entry=0x7fcc534d0c00 , > body_data=body_data@entry=0x7fcc4d14cd50, > handler=handler@entry=0x7fcc534d0fe0 , > handler_data=handler_data@entry=0x7fcc4d14cd50 > , pre_unwind_handler=pre_unwind_handler@entry=0x7fcc534d0d90 > , pre_unwind_handler_data=0x127cff0) at > throw.c:207 > #6 0x00007fcc534d1381 in scm_i_with_continuation_barrier > (body=body@entry=0x7fcc534d0c00 , > body_data=body_data@entry=0x7fcc4d14cd50, > handler=handler@entry=0x7fcc534d0fe0 , > handler_data=handler_data@entry=0x7fcc4d14cd50, > pre_unwind_handler=pre_unwind_handler@entry=0x7fcc534d0d90 > , pre_unwind_handler_data=0x127cff0) at > continuations.c:455 > #7 0x00007fcc534d1415 in scm_c_with_continuation_barrier > (func=, data=) at continuations.c:551 > #8 0x00007fcc5354e6dc in with_guile_and_parent > (base=base@entry=0x7fcc4d14cdb0, data=data@entry=0x7fcc4d14cde0) at > threads.c:906 > #9 0x00007fcc53222302 in GC_call_with_stack_base > (fn=fn@entry=0x7fcc5354e690 , > arg=arg@entry=0x7fcc4d14cde0) at misc.c:1553 > #10 0x00007fcc5354eac8 in scm_i_with_guile_and_parent > (parent=, data=, func=) > at threads.c:949 > #11 scm_with_guile (func=, data=) at > threads.c:955 > #12 0x00000000004008bb in a_libguile_thread_ (unused=0x0) at > corruption_guile.c:11 > #13 0x00007fcc53226f6e in GC_inner_start_routine (sb= variable: value has been optimized out>, arg= value has been optimized out>) at pthread_start.c:56 > #14 0x00007fcc53222302 in GC_call_with_stack_base (fn=, > arg=) at misc.c:1553 > #15 0x00007fcc52ff40a4 in start_thread (arg=0x7fcc4d14d700) at > pthread_create.c:309 > #16 0x00007fcc52d28ccd in clone () at . > ./sysdeps/unix/sysv/linux/x86_64/clone.S:111 > ``` > > I thought at first it was a problem with libgc but the given program > run without problems. > ``` > #include > #include > #define GC_THREADS 1 > #define GC_NO_THREAD_REDIRECTS 1 > #include > #include > > static void *a_lib_gc_thread(void *unused) { > void *a; > for (int i = 0; i < 100; ++i) { > a = GC_generic_malloc(524288, 6); > } > GC_free(a); > } > > static void do_mallocs(void) { > void *a[100]; > for (int i = 0; i < 100; ++i) { > a[i] = malloc(356); > } > for (int i = 0; i < 100; ++i) { > free(a[i]); > } > } > > int main(int argc, char *argv[]) { > pthread_t pth[10]; > for (int i = 0; i < 10; ++i) { > GC_pthread_create(pth + i, NULL, a_lib_gc_thread, NULL); > } > do_mallocs(); > for (int i = 0; i < 10; ++i) { > GC_pthread_join(pth[i], NULL); > } > return 0; > } > ``` > I also tried to replace malloc by scm_malloc with no luck. > > Regards, Anthonin