From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludo-mXXj517/zsQ@public.gmane.org (Ludovic =?iso-8859-1?Q?Court=E8s?=) Newsgroups: gmane.comp.programming.garbage-collection.boehmgc,gmane.lisp.guile.bugs Subject: Calling =?utf-8?b?4oCYR0NfSU5JVOKAmQ==?= from a secondary thread Date: Fri, 15 Apr 2011 23:35:04 +0200 Message-ID: <87tydzdwqf.fsf_-_@gnu.org> References: <238A96A773B3934685A7269CC8A8D04272EFCB8D2E@GVW0436EXB.americas.hpqcorp.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1302903736 5773 80.91.229.12 (15 Apr 2011 21:42:16 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 15 Apr 2011 21:42:16 +0000 (UTC) Cc: bug-guile-mXXj517/zsQ@public.gmane.org To: gc-V9/bV5choksm30D7ZfaTJw@public.gmane.org Original-X-From: gc-bounces-V9/bV5choksm30D7ZfaTJw@public.gmane.org Fri Apr 15 23:42:10 2011 Return-path: Envelope-to: gcpgb-gc-Uylq5CNFT+jYtjvyW6yDsg@public.gmane.org Original-Received: from gundega.hpl.hp.com ([192.6.19.190]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QAqmH-0000B6-1H for gcpgb-gc-Uylq5CNFT+jYtjvyW6yDsg@public.gmane.org; Fri, 15 Apr 2011 23:42:09 +0200 Original-Received: from mailhub-pa1.hpl.hp.com (mailhub-pa1.hpl.hp.com [15.25.115.25]) by gundega.hpl.hp.com (8.14.4/8.14.4/HPL-PA Relay) with ESMTP id p3FLfcQu015229 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 15 Apr 2011 14:41:38 -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 p3FLfbNr028597 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 15 Apr 2011 14:41:38 -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 p3FLcqJA007882; Fri, 15 Apr 2011 14:38:54 -0700 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 p3FLcoOP007879 for ; Fri, 15 Apr 2011 14:38:50 -0700 Original-Received: from lo.gmane.org (lo.gmane.org [80.91.229.12]) by gundega.hpl.hp.com (8.14.4/8.14.4/HPL-PA Relay) with ESMTP id p3FLcdBf015171 for ; Fri, 15 Apr 2011 14:38:46 -0700 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1QAqfi-0004vL-CK for gc-V9/bV5choksm30D7ZfaTJw@public.gmane.org; Fri, 15 Apr 2011 23:35:22 +0200 Original-Received: from reverse-83.fdn.fr ([80.67.176.83]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 15 Apr 2011 23:35:22 +0200 Original-Received: from ludo by reverse-83.fdn.fr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 15 Apr 2011 23:35:22 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Followup-To: gmane.comp.programming.garbage-collection.boehmgc Original-Lines: 94 Original-X-Complaints-To: usenet-mkLwACOSqtU9smdsby/KFg@public.gmane.org X-Gmane-NNTP-Posting-Host: reverse-83.fdn.fr X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 26 Germinal an 219 de la =?iso-8859-1?Q?R=E9volution?= X-PGP-Key-ID: 0xEA52ECF4 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 83C4 F8E5 10A3 3B4C 5BEA D15D 77DD 95E2 EA52 ECF4 X-OS: x86_64-unknown-linux-gnu User-Agent: Gnus/5.110015 (No Gnus v0.15) Emacs/23.3 (gnu/linux) Cancel-Lock: sha1:FxC/W8jk52BRaW1f7ZaGHCJfEbw= X-Scanned-By: MIMEDefang 2.71 on 15.0.48.190 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 X-MIME-Autoconverted: from 8bit to quoted-printable by gundega.hpl.hp.com id p3FLfcQu015229 Xref: news.gmane.org gmane.comp.programming.garbage-collection.boehmgc:4490 gmane.lisp.guile.bugs:5492 Archived-At: Hi Hans, "Boehm, Hans" writes: >> From: Andy Wingo >> ... >> [From Ivan:] >> > 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. >>=20 >> We can add some documentation to this regard in the manual, if needed. >> But is there no way to get around this, and do the right thing? For >> example, to avoid implicit GC initialization in response to a >> pthread_create. >>=20 > The problem is that GC_pthread_create needs to allocate memory, and rel= ies on some other GC state. Hence the GC must have been initialized for = it to work. > > For newer collectors, it might be possible to instead arrange for pthre= ad_create not to be redirected to GC_pthread_create, and for threads that= need to be known to the GC to register themselves. I haven't thought th= rough whether that might be feasible here. With current CVS, it doesn=E2=80=99t seem to be possible to call GC_INIT = from a secondary thread, as in this example: --8<---------------cut here---------------start------------->8--- #define GC_THREADS 1 #define GC_NO_THREAD_REDIRECTS 1 #include #include #include static void * thread (void *arg) { GC_INIT (); GC_MALLOC (123); GC_MALLOC (12345); return NULL; } int main (int argc, char *argv[]) { pthread_t t; pthread_create (&t, NULL, thread, NULL); pthread_join (t, NULL); return EXIT_SUCCESS; } /* Local Variables: compile-command: "gcc -Wall t.c `pkg-config bdw-gc --cflags --libs`" End: */ --8<---------------cut here---------------end--------------->8--- This program segfaults: --8<---------------cut here---------------start------------->8--- Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7ffff73e5700 (LWP 772)] GC_push_all_eager (bottom=3D, top=3D) at ../mark.c:1528 1528 GC_PUSH_ONE_STACK(q, p); (gdb) thread apply all bt Thread 2 (Thread 0x7ffff73e5700 (LWP 772)): #0 GC_push_all_eager (bottom=3D, top=3D) at ../mark.c:1528 #1 0x00007ffff7b91d4a in GC_push_all_stacks () at ../pthread_stop_world.= c:336 #2 0x00007ffff7b898c4 in GC_mark_some (cold_gc_frame=3D0x7ffff73e4e0c ""= ) at ../mark.c:373 #3 0x00007ffff7b800e8 in GC_stopped_mark (stop_func=3D0x7ffff7b7fbf0 ) at ../alloc.c:639 #4 0x00007ffff7b80880 in GC_try_to_collect_inner (stop_func=3D0x7ffff7b7= fbf0 ) at ../alloc.c:457 #5 0x00007ffff7b8bb19 in GC_init () at ../misc.c:991 #6 0x0000000000400865 in thread () #7 0x00007ffff75f0cec in start_thread () from /nix/store/vxycd107wjbhcj7= 20hzkw2px7s7kr724-glibc-2.12.2/lib/libpthread.so.0 #8 0x00007ffff78d81ed in clone () from /nix/store/vxycd107wjbhcj720hzkw2= px7s7kr724-glibc-2.12.2/lib/libc.so.6 Thread 1 (Thread 0x7ffff7ff5700 (LWP 769)): #0 0x00007ffff75f1f15 in pthread_join () from /nix/store/vxycd107wjbhcj7= 20hzkw2px7s7kr724-glibc-2.12.2/lib/libpthread.so.0 #1 0x00000000004008bb in main () --8<---------------cut here---------------end--------------->8--- Is it expected? > Another imperfect solution might be to set all_interior_pointers and pr= obably call GC_INIT in a constructor, either a C++ constructor, or a C fu= nction that's suitably attributed. That still fails if other constructor= s run into this problem before our constructor runs. If GC_INIT must be called from the main thread, then constructors would seem to be the only way to get it called. Thanks, Ludo=E2=80=99.