From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?UTF-8?B?5Lqa5YWJ5ZSQ?= Newsgroups: gmane.lisp.guile.bugs Subject: guile 2.0.1 fluid *current-language* failed to initialize in multi-thread app Date: Mon, 30 May 2011 01:16:44 +0800 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: dough.gmane.org 1306695370 2167 80.91.229.12 (29 May 2011 18:56:10 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 29 May 2011 18:56:10 +0000 (UTC) To: bug-guile@gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Sun May 29 20:56:07 2011 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QQl9i-0003I6-Hs for guile-bugs@m.gmane.org; Sun, 29 May 2011 20:56:06 +0200 Original-Received: from localhost ([::1]:48638 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QQl9i-0005Ol-6W for guile-bugs@m.gmane.org; Sun, 29 May 2011 14:56:06 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:40619) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QQjbb-0004Lm-DO for bug-guile@gnu.org; Sun, 29 May 2011 13:16:48 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QQjbZ-0005Dq-Np for bug-guile@gnu.org; Sun, 29 May 2011 13:16:47 -0400 Original-Received: from mail-qy0-f169.google.com ([209.85.216.169]:47515) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QQjbZ-0005De-Lg for bug-guile@gnu.org; Sun, 29 May 2011 13:16:45 -0400 Original-Received: by qyk2 with SMTP id 2so611229qyk.0 for ; Sun, 29 May 2011 10:16:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:date:message-id:subject:from:to :content-type; bh=cc3y/Jonq9CABQoBwj1Eox8T4o8w+bsXrNdJU9pACuw=; b=vqm/49vcxEAKAmq7dQ4EemktiUXAb9zKxYePjmmcUBYmXQwNKcpwjN3/Av1o28nGUQ js09O9dAnQIN2fYbz6/z2mvqsc1IrxhaMhqA/T/7mh88PxUf4uLZm2uzikQI4f6cktwu hqhPKsYITiSe8/ek4Cn4A5ICrb9W1ngXREN28= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=OpUWhcjQHtvP4idTABV1fJJTr3xXff3/efwqYS+xMwvzqFCsd3GmbZpG+78BhQSwWW Lrmg/9ONa15WQhtuRCG7kTC1qK8d66T50H2/KDBgq2mqjsCp3halNBG+LscYVYrhvoXb 3AAAoxe1wiwmSeDVkKNPl86LIv56TpLk9tFrw= Original-Received: by 10.229.225.208 with SMTP id it16mr2744433qcb.182.1306689404810; Sun, 29 May 2011 10:16:44 -0700 (PDT) Original-Received: by 10.229.106.211 with HTTP; Sun, 29 May 2011 10:16:44 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.216.169 X-Mailman-Approved-At: Sun, 29 May 2011 14:56:03 -0400 X-BeenThere: bug-guile@gnu.org X-Mailman-Version: 2.1.14 Precedence: list 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-bounces+guile-bugs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.bugs:5624 Archived-At: I intend to use two thread eval some string in my app, but I found the the child thread will throw an exception when execute 'scm_eval_string' function. I print out the call stack and check the source code, I found that the *current-language* variable is '#f" in the child thread. I think there must be something wrong. Test environment: Linux tyg-THINK 2.6.37 #7 SMP Tue Feb 22 11:25:54 CST 2011 x86_64 Intel(R) Core(TM) i3 CPU M 370 @ 2.40GHz GenuineIntel GNU/Linux x86_64-unknown-linux-gnu (slackware 13.2) gcc 4.4.4 guile 2.0.1 build with '--prefix=/usr/local/stow/guile-2.0.1' 'BDW_GC_CFLAGS=-I/usr/local/include' 'BDW_GC_LIBS=-L/usr/local/libs -lgc' BWD gc 7.1 with default config Following code will reproduce the bug. g++ -g -Wall -pipe -pthread -I/usr/local/stow/guile-2.0.1/include/guile/2.0 -lguile-2.0 bug_repro.cpp -o bug_repro // --------------------------------------------------------------------------------------------------------------------------------------------------- #include #include #include #define MAXLINE 1024 static SCM catch_body(void *data) { char buf[MAXLINE]; char *s = (char*)data; snprintf(buf, MAXLINE, "%s", s); SCM ret_val = scm_eval_string(scm_from_locale_string(buf)); return ret_val; } static SCM catch_handler(void *data, SCM tag, SCM throw_args) { char *stag = scm_to_locale_string(scm_symbol_to_string(tag)); printf("--- catch %s: %s\n", stag, (char*)data); free(stag); return SCM_BOOL_T; } static SCM preunwind_handler(void *data, SCM key, SCM parameters) { /* Capture the stack here: */ *(SCM *)data = scm_make_stack (SCM_BOOL_T, SCM_EOL); return SCM_BOOL_T; } static const char * const str1 = "(display \"This is string A\") (newline)"; static const char * const str2 = "(display \"This is string B\") (newline)"; void *eval_string(void *argp) { char *str = (char*)argp; SCM captured_stack = SCM_BOOL_F; // eval string. scm_c_catch (SCM_BOOL_T, catch_body, str, catch_handler, str, preunwind_handler, &captured_stack); // print call stack on error. SCM port = scm_open_output_string (); if (captured_stack != SCM_BOOL_F) { scm_display_backtrace (captured_stack, port, SCM_BOOL_F, SCM_BOOL_F); SCM scm_str = scm_get_output_string (port); char *stack_str = scm_to_locale_string(scm_str); printf("%s", stack_str); scm_close_output_port(port); } return 0; } static void* run_thread(void * arg) { scm_with_guile(eval_string, (void*)str2); return 0; } static void inner_main (void *closure, int argc, char **argv) { // eval string A eval_string((void*)str1); pthread_t tid; // create new thread and eval string B if (pthread_create(&tid, 0, run_thread, 0) < 0) { exit(1); } pthread_join(tid, 0); exit(0); } int main(int argc, char** argv) { scm_boot_guile(argc, argv, inner_main, 0); } // -----------------------------------------------------------------------------------------------------------------------------------------------------------------------