From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Han-Wen Nienhuys Newsgroups: gmane.lisp.guile.devel Subject: Re: Race condition in threading code? Date: Wed, 03 Sep 2008 01:56:27 -0300 Message-ID: <48BE18FB.5020804@xs4all.nl> References: <2bc5f8210808161142n2b415569y8499f3efafb4a@mail.gmail.com> <871w05x7zu.fsf@gnu.org> Reply-To: hanwen@xs4all.nl NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1220417909 16828 80.91.229.12 (3 Sep 2008 04:58:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 3 Sep 2008 04:58:29 +0000 (UTC) Cc: Marius Vollmer To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Wed Sep 03 06:59:24 2008 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KakSh-0006bE-Jz for guile-devel@m.gmane.org; Wed, 03 Sep 2008 06:59:23 +0200 Original-Received: from localhost ([127.0.0.1]:53315 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KakRi-0007aL-Ie for guile-devel@m.gmane.org; Wed, 03 Sep 2008 00:58:22 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KakRR-0007TE-Uz for guile-devel@gnu.org; Wed, 03 Sep 2008 00:58:06 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KakRQ-0007S4-Ic for guile-devel@gnu.org; Wed, 03 Sep 2008 00:58:04 -0400 Original-Received: from [199.232.76.173] (port=46230 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KakRQ-0007Rq-Ag for guile-devel@gnu.org; Wed, 03 Sep 2008 00:58:04 -0400 Original-Received: from main.gmane.org ([80.91.229.2]:52123 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KakRP-0003Kc-HO for guile-devel@gnu.org; Wed, 03 Sep 2008 00:58:04 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1KakRK-0006B4-F4 for guile-devel@gnu.org; Wed, 03 Sep 2008 04:57:58 +0000 Original-Received: from 201.80.3.52 ([201.80.3.52]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 03 Sep 2008 04:57:58 +0000 Original-Received: from hanwen by 201.80.3.52 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 03 Sep 2008 04:57:58 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 75 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 201.80.3.52 User-Agent: Thunderbird 2.0.0.16 (X11/20080723) In-Reply-To: X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:7577 Archived-At: Han-Wen Nienhuys escreveu: >>> ERROR: srfi-18.test: thread-start!: >>> thread activates only after start >>> - arguments: ((syntax-error "memoization" >>> "In file ~S, line ~S: ~A ~S in expression ~S." >>> ("/home/lilydev/vc/guile/srfi/srfi-18.scm" 135 >>> "Bad binding" ct >>> (let (ct (current-thread)) >>> #@let (or (hashq-ref thread-exception-handlers ct) >>> (hashq-set! thread-exception-handlers ct >>> (list initial-handler))))) #f)) >> I'm seeing this as well, but it's a `#@let*' here (single-binding `let's >> are memoized as `#@let*'): >> >> ((syntax-error "memoization" >> "In file ~S, line ~S: ~A ~S in expression ~S." >> ("/home/ludo/src/guile/srfi/srfi-18.scm" 138 >> "Bad binding" >> ct >> (#@let* (ct (#>)) >> (#@or (#> >> #> #@0-0) >> (#> #> #@0-0 (#> #>)) >> ))) >> #f)) >> >> It can be reproduced, but very infrequently, with this program: >> >> (use-modules (ice-9 threads)) >> >> (define (foo x y) >> (let ((z (+ x y))) >> (let ((a (+ z 1))) >> (let ((b (- a 2))) >> (let ((c (* b 3))) >> c))))) >> >> (define (entry) >> (foo 1 2)) >> >> (for-each (lambda (i) (make-thread entry)) >> (iota 123)) >> >> My explanation is that the `let*' memoizer, aka. `scm_m_letstar ()', is >> not thread-safe; it's clearly not atomic, and it's of course not >> protected by a mutex or so. > > Is that the only one? > > SCM > scm_m_let (SCM expr, SCM env) > ... > /* plain let */ > SCM rvariables; > SCM inits; > transform_bindings (bindings, expr, &rvariables, &inits); > > { > const SCM new_body = m_body (SCM_IM_LET, SCM_CDR (cdr_expr)); > const SCM new_tail = scm_cons2 (rvariables, inits, new_body); > SCM_SETCAR (expr, SCM_IM_LET); > // ****!!! > SCM_SETCDR (expr, new_tail); > > What happens if another thread tries to evaluate expr at the place marked ****!!! ? > > At the very least, we should have an atomic SCM_SETCELL() which overwrites car and > cdr atomically. Anyone? Does anyone still understand how the evaluator works? (if not, let's move to the VM earlier than later.) -- Han-Wen Nienhuys - hanwen@xs4all.nl - http://www.xs4all.nl/~hanwen