From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Linas Vepstas" Newsgroups: gmane.lisp.guile.user Subject: bug: defining things in different threads Date: Tue, 11 Nov 2008 12:57:40 -0600 Message-ID: <3ae3aa420811111057k597b510eyed0f351429b0d61e@mail.gmail.com> Reply-To: linasvepstas@gmail.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1226429895 14276 80.91.229.12 (11 Nov 2008 18:58:15 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 11 Nov 2008 18:58:15 +0000 (UTC) To: "Guile User Mailing List" Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Tue Nov 11 19:59:14 2008 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KzySH-0001jY-K7 for guile-user@m.gmane.org; Tue, 11 Nov 2008 19:59:13 +0100 Original-Received: from localhost ([127.0.0.1]:48199 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KzyRA-0003oY-0V for guile-user@m.gmane.org; Tue, 11 Nov 2008 13:58:04 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KzyQp-0003o6-T6 for guile-user@gnu.org; Tue, 11 Nov 2008 13:57:43 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KzyQo-0003nh-HG for guile-user@gnu.org; Tue, 11 Nov 2008 13:57:42 -0500 Original-Received: from [199.232.76.173] (port=42573 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KzyQo-0003ne-Dk for guile-user@gnu.org; Tue, 11 Nov 2008 13:57:42 -0500 Original-Received: from yw-out-1718.google.com ([74.125.46.158]:47715) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KzyQn-00059c-Rn for guile-user@gnu.org; Tue, 11 Nov 2008 13:57:42 -0500 Original-Received: by yw-out-1718.google.com with SMTP id 9so16332ywk.66 for ; Tue, 11 Nov 2008 10:57:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:reply-to :to:subject:mime-version:content-type:content-transfer-encoding :content-disposition; bh=uYwEMZ3dbEXNMxRDEXJB3P/r9XYSneQXYQMqeZna8/4=; b=GvZwJ1yKEZpD2v/WxECFB0C3qWW7jtWLvIOo3l2KE4Acq6V+eCNPaLethTkzGeeAVZ 5rLuV0DmhceX4xsG3jPb0lvEehZwhjyPb8EoqJKXdgoyV/MimavPWPHQZVOfSkZs7Zwm 7HrJLNQmTfWwBBshagxqxIpPSGAcMrttmHz58= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:reply-to:to:subject:mime-version:content-type :content-transfer-encoding:content-disposition; b=FCgxMeqa3CnyyxB+q3AvLh+28mBApvZLHaVkirxzkkjyd84Fib4Ai2t9x6mANnCqRn LkcogvaccJYpk5ToFWAu9/+Vu39P1Rl9KdTnF3kSicTQtDx+o5H+X545D/YRj+kjXC1K 4UO6xdW3fRGZYJvc+XKAHuxcITkRW/56SjrM8= Original-Received: by 10.100.134.16 with SMTP id h16mr3356628and.42.1226429860083; Tue, 11 Nov 2008 10:57:40 -0800 (PST) Original-Received: by 10.100.249.18 with HTTP; Tue, 11 Nov 2008 10:57:40 -0800 (PST) Content-Disposition: inline X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:6874 Archived-At: Hi, I am finding that things defined in one thread are not always visible in another. This seems to be due to some threads having a different current-module than others. I think this is a bug. The example code below shows the issue. Help, comments appreciated. --linas /** * Guile threading bug/unexpected behaviour. * * Two posix threads are created. The first thread runs, and defines * something. The second thread tries to access the thing defined by * the first. But, due to some "unexpected" threading behaviour, the * things defined in the first thread are not visible to the first. * I'm pretty convinced this is a bug, and am hunting it down now. * * The printed output of this program, for me, under guile1.8.5, is * * HEllo, thread one is running * Goodbye, thread one is exiting * HEllo, thread two is running * ERROR: Unbound variable: x * Goodbye, thread two is exiting * Main is exiting * * To get a better idea of what's going on, it seems to have something * to do with the current module. By turning on print debugging, the * output, for me, becomes: * * HEllo, thread one is running * thread one had output: * the root module is # * the current module is # * * Goodbye, thread one is exiting * HEllo, thread two is running * thread two had output: * the root module is # * the current module is # * * ERROR: Unbound variable: x * Goodbye, thread two is exiting * Main is exiting */ #include #include #include #include void prtdbg(const char * id) { // #define SHOW_STUFF 1 #ifdef SHOW_STUFF SCM outport = scm_open_output_string(); scm_set_current_output_port(outport); scm_c_eval_string ("(display \"the root module is \")\n"); scm_c_eval_string ("(display the-root-module)\n"); scm_c_eval_string ("(newline)\n"); scm_c_eval_string ("(display \"the current module is \")\n"); scm_c_eval_string ("(display (current-module))\n"); scm_c_eval_string ("(newline)\n"); SCM out = scm_get_output_string(outport); char * str = scm_to_locale_string(out); // scm_truncate_file(outport, scm_from_uint16(0)); printf("%s had output:\n%s\n", id, str); #endif } void * scm_one (void *p) { prtdbg("thread one"); scm_c_eval_string ("(define x \"asddf\")\n"); } void * scm_two (void *p) { prtdbg("thread two"); scm_c_eval_string ("(display x)\n"); } static void * thread_one (void * arg) { printf("HEllo, thread one is running\n"); scm_with_guile(scm_one, NULL); printf("Goodbye, thread one is exiting\n"); return NULL; } static void * thread_two (void * arg) { printf("HEllo, thread two is running\n"); scm_with_guile(scm_two, NULL); printf("Goodbye, thread two is exiting\n"); return NULL; } main() { int rc; pthread_attr_t attr; pthread_t t1, t2; pthread_attr_init(&attr); rc = pthread_create(&t1, &attr, thread_one, NULL); if(rc) { fprintf(stderr, "Fatal error: can't create thread one\n"); exit(1); } sleep(1); rc = pthread_create(&t2, &attr, thread_two, NULL); if(rc) { fprintf(stderr, "Fatal error: can't create thread two\n"); exit(1); } sleep(5); printf("Main is exiting\n"); }