From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ivan Maidanski Newsgroups: gmane.comp.programming.garbage-collection.boehmgc,gmane.lisp.guile.bugs Subject: =?utf-8?Q?Re=3A__pthreads_and_libgc?= Date: Sat, 19 Mar 2011 22:18:17 +0300 Message-ID: References: Reply-To: Ivan Maidanski NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1300562575 14081 80.91.229.12 (19 Mar 2011 19:22:55 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 19 Mar 2011 19:22:55 +0000 (UTC) Cc: bug-guile , gc-V9/bV5choksm30D7ZfaTJw@public.gmane.org To: Andy Wingo Original-X-From: gc-bounces-V9/bV5choksm30D7ZfaTJw@public.gmane.org Sat Mar 19 20:22:50 2011 Return-path: Envelope-to: gcpgb-gc-Uylq5CNFT+jYtjvyW6yDsg@public.gmane.org Original-Received: from madara.hpl.hp.com ([192.6.19.124]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Q11jZ-0006Y4-0P for gcpgb-gc-Uylq5CNFT+jYtjvyW6yDsg@public.gmane.org; Sat, 19 Mar 2011 20:22:45 +0100 Original-Received: from mailhub-pa1.hpl.hp.com (mailhub-pa1.hpl.hp.com [15.25.115.25]) by madara.hpl.hp.com (8.14.4/8.14.4/HPL-PA Relay) with ESMTP id p2JJMEcG015737 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Sat, 19 Mar 2011 12:22:14 -0700 Original-Received: from napali.hpl.hp.com (napali.hpl.hp.com [15.4.89.123]) by mailhub-pa1.hpl.hp.com (8.14.3/8.14.3/HPL-PA Hub) with ESMTP id p2JJMDiY002117 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Sat, 19 Mar 2011 12:22:14 -0700 Original-Received: from napali.hpl.hp.com (localhost.hpl.hp.com [127.0.0.1]) by napali.hpl.hp.com (8.13.4/8.13.4/HPL-PA send-recv-int) with ESMTP id p2JJJMXa002176; Sat, 19 Mar 2011 11:19:25 -0800 Original-Received: from gundega.hpl.hp.com (gundega.hpl.hp.com [15.0.48.190]) by napali.hpl.hp.com (8.13.4/8.13.4/HPL-PA send-recv-int) with ESMTP id p2JJJJCE002173 for ; Sat, 19 Mar 2011 11:19:19 -0800 Original-Received: from f119.mail.ru (f119.mail.ru [217.69.129.112]) by gundega.hpl.hp.com (8.14.4/8.14.4/HPL-PA Relay) with ESMTP id p2JJJ6CA029393 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Sat, 19 Mar 2011 12:19:14 -0700 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mail.ru; s=mail; h=Message-Id:Content-Transfer-Encoding:Content-Type:Reply-To:In-Reply-To:References:Date:Mime-Version:Subject:Cc:To:From; bh=XNpqMA8XgumJsnQwGN3GBdzIily+tuMTncHiY1Urv6U=; b=FBxU8nsTCCrUQILEBmm0puV+HgZV1gnBF6H/B9FfEQaptKhIrzjUbO3wD1hbMgEfLYuI5TxERCT13uYDv1QppqQ/i0EJNfBYPodm5UQq50oTaEwKCrZwH+zChB1NgXrY; Original-Received: from mail by f119.mail.ru with local id 1Q11fF-0001dv-00; Sat, 19 Mar 2011 22:18:17 +0300 Original-Received: from [109.225.46.145] by e.mail.ru with HTTP; Sat, 19 Mar 2011 22:18:17 +0300 X-Mailer: mPOP Web-Mail 2.19 X-Originating-IP: [109.225.46.145] In-Reply-To: X-Spam: Not detected X-Mras: Ok X-Scanned-By: MIMEDefang 2.71 on 15.0.152.124 X-Scanned-By: MIMEDefang 2.71 on 192.6.19.190 X-BeenThere: gc-V9/bV5choksm30D7ZfaTJw@public.gmane.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Garbage Collector bugs/discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: gc-bounces-V9/bV5choksm30D7ZfaTJw@public.gmane.org Errors-To: gc-bounces-V9/bV5choksm30D7ZfaTJw@public.gmane.org Xref: news.gmane.org gmane.comp.programming.garbage-collection.boehmgc:4435 gmane.lisp.guile.bugs:5345 Archived-At: Hi Andy, Fri, 18 Mar 2011 21:56:04 +0100 Andy Wingo : > Hello list, > > I was tracking down a bug in Guile, got to a sticky situation, and could > use some input. Let me first show you the code. > > #include > #include > #include > #include > > static void *thread_with_guile(void *null) > { > return NULL; > } > > static void *the_thread(void *args) > { > scm_with_guile (thread_with_guile, NULL); > return NULL; > } > > > int main(void) > { > int n; > > for (n = 0; n < 10000; n++) { > pthread_t ptid; > fprintf (stderr, "%d: create", n); > pthread_create(&ptid, NULL, the_thread, NULL); > void *ret; > fprintf (stderr, " join"); > pthread_join(ptid, &ret); > fprintf (stderr, " finished.\n"); > } > > return 0; > } > > I don't presume that you will compile it, but if you do, you can do so > with "gcc -o test test.c `pkg-config --cflags --libs guile-2.0`". > > As you see, it creates a bunch of threads, and does something within > "guile mode" on each of them. The use case is obviously for some big > threaded application with plugins, and you don't know what thread will > see Guile first. > > The first scm_with_guile call will initialize Guile, which does a > GC_INIT, which basically goes like this: > > GC_all_interior_pointers = 0; > GC_INIT (); GC_all_interior_pointers cannot be modified after GC_INIT according to the spec. GC_set_all_interior_pointers() has an assertion check for this condition. > > However, libgc appears already to have been initialized when this > happens, automagically, because of pthreads. If I run the program under > GDB, it happens here: > > Breakpoint 1, GC_init () at misc.c:634 > 634 { > (gdb) thr apply all bt > > Thread 1 (Thread 0x7ffff78df700 (LWP 14166)): > #0 GC_init () at misc.c:634 > #1 0x0000003fc8e1455e in GC_generic_malloc_inner (lb=56, k=1) at malloc.c:119 > #2 0x0000003fc8e1f4ce in GC_pthread_create (new_thread=0x7fffffffe020, > attr=0x0, start_routine=0x4007e3 , > arg=0x0) at pthread_support.c:1469 > #3 0x0000000000400853 in main () > > Unhappily though, the initialization is done with > GC_all_interior_pointers == 1. So later after Guile initializes, it > gets a segfault: > > Program received signal SIGSEGV, Segmentation fault. > 0x0000003fc8e0f6e3 in GC_is_black_listed (h=0x655000, len= out>) at blacklst.c:233 > 233 if (get_pht_entry_from_index(GC_old_normal_bl, index) > (gdb) thr apply all bt > > Thread 2 (Thread 0x7ffff78dd700 (LWP 14169)): > #0 0x0000003fc8e0f6e3 in GC_is_black_listed (h=0x655000, len= out>) at blacklst.c:233 > ... > > In this case `GC_old_normal_bl' is NULL, as it is only initialized to a > valid value if GC_all_interior_pointers is zero, which was not the case > when libgc was automatically initialized. > > What should we do here? You could compile GC without -D ALL_INTERIOR_POINTERS. But, anyway, it is recommended to initialize GC explicitly (i.e. by GC_INIT), so placing GC_INIT() (together with GC_set_all_interior_pointer) to the beginning of your main() should be the best way out. Regards. > > Thanks, > > Andy > -- > http://wingolog.org/