From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.bugs Subject: bug#32786: (system* ...) call somehow interferes with atomic-box on armv7l Date: Fri, 21 Sep 2018 17:26:27 -0400 Message-ID: <87fty2v8xo.fsf@netris.org> References: <20180920171306.GA9185@k> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1537565108 28123 195.159.176.226 (21 Sep 2018 21:25:08 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 21 Sep 2018 21:25:08 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) Cc: 32786@debbugs.gnu.org To: =?UTF-8?Q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB_?= =?UTF-8?Q?=D0=91=D0=B0=D1=85=D1=82=D0=B5=D1=80=D0=B5=D0=B2?= Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Fri Sep 21 23:25:04 2018 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g3Sv9-0007CN-AC for guile-bugs@m.gmane.org; Fri, 21 Sep 2018 23:25:03 +0200 Original-Received: from localhost ([::1]:57428 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3SxF-00020f-Ss for guile-bugs@m.gmane.org; Fri, 21 Sep 2018 17:27:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55478) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3Sx8-00020a-RN for bug-guile@gnu.org; Fri, 21 Sep 2018 17:27:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g3Sx4-0000E7-PH for bug-guile@gnu.org; Fri, 21 Sep 2018 17:27:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:44234) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g3Sx4-0000DS-8r for bug-guile@gnu.org; Fri, 21 Sep 2018 17:27:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1g3Sx3-0004DP-Ri for bug-guile@gnu.org; Fri, 21 Sep 2018 17:27:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Mark H Weaver Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Fri, 21 Sep 2018 21:27:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32786 X-GNU-PR-Package: guile X-GNU-PR-Keywords: Original-Received: via spool by 32786-submit@debbugs.gnu.org id=B32786.153756520816183 (code B ref 32786); Fri, 21 Sep 2018 21:27:01 +0000 Original-Received: (at 32786) by debbugs.gnu.org; 21 Sep 2018 21:26:48 +0000 Original-Received: from localhost ([127.0.0.1]:48492 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g3Swq-0004Cx-Ei for submit@debbugs.gnu.org; Fri, 21 Sep 2018 17:26:48 -0400 Original-Received: from world.peace.net ([64.112.178.59]:40778) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g3Swo-0004Ck-IQ for 32786@debbugs.gnu.org; Fri, 21 Sep 2018 17:26:47 -0400 Original-Received: from mhw by world.peace.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1g3Swh-0004kl-0e; Fri, 21 Sep 2018 17:26:39 -0400 In-Reply-To: <20180920171306.GA9185@k> ("=?UTF-8?Q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB_?= =?UTF-8?Q?=D0=91=D0=B0=D1=85=D1=82=D0=B5=D1=80=D0=B5=D0=B2?="'s message of "Thu, 20 Sep 2018 22:13:06 +0500") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-guile@gnu.org 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" Xref: news.gmane.org gmane.lisp.guile.bugs:9164 Archived-At: Hi, =D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB =D0=91=D0=B0=D1=85=D1=82=D0=B5=D1=80= =D0=B5=D0=B2 writes: > I attach the code sample, which expected behaviour is: > > 1. to periodically restart thread, which executes =C2=ABsleep 1s=C2=BB = with > system* call; > > 2. and then to check if it should repeat the execution. >=20=20=20 > The flag, which controls that re-execution is managed by another thread > through atomic-box primitive. > > The code does not run as expected: the sleep executing sleep starts > once, and change seems to remain invisible to main thread. Can you describe in more detail the behavior you are seeing? What messages do you see on stderr from your 'dump' calls when it gets stuck? What state is the atomic box left in? I see a couple of problems with the code below: * Two threads write concurrently to the same port, namely (current-error-port). You should use thread synchronization to ensure that operations to a given port are serialized. * There's a race condition when the atomic box is in the #:accepted state. If the main thread finds the box in that state, it changes the state to #:need-to-sleep, which will apparently cause the other thread to sleep again. I'm not sure if these problems could explain what you're seeing. Regards, Mark > The code works as expected, when: > > 1. (sleep 1) is used instead (system* "sleep" "1s"); > 2. running the code on x86_64 cpus. > > The use of affinity mask > > taskset 0x01 guile test.scm > > does not help. > > - MB. Respectfully > > P.S. Additional information: > > $ guile --version=20=20 > guile (GNU Guile) 2.2.4 > Copyright (C) 2018 Free Software Foundation, Inc. > > License LGPLv3+: GNU LGPL 3 or later . > This is free software: you are free to change and redistribute it. > There is NO WARRANTY, to the extent permitted by law. > > $ sh config.guess > armv7l-unknown-linux-gnueabihf > > $ pacman -Qi guile=20 > Name : guile > Version : 2.2.4-1 > Description : Portable, embeddable Scheme implementation written in C > Architecture : armv7h > URL : https://www.gnu.org/software/guile/ > Licenses : GPL > Groups : None > Provides : None > Depends On : gmp libltdl ncurses texinfo libunistring gc libffi > Optional Deps : None > Required By : make > Optional For : gnutls > Conflicts With : None > Replaces : None > Installed Size : 40.83 MiB > Packager : Arch Linux ARM Build System > Build Date : Tue 03 Jul 2018 04:47:53 PM +05 > Install Date : Mon 09 Jul 2018 01:02:48 PM +05 > Install Reason : Installed as a dependency for another package > Install Script : No > Validated By : Signature > > (use-modules (ice-9 atomic) > (ice-9 threads)) > > (define dump > (let ((p (current-error-port))) > (lambda (fmt . args) (apply format p fmt args)))) > > (define state (make-atomic-box #:nothing-to-do)) > > (define (expect e v) > (when (not (eq? e v)) > (error "Protocol violation; (expecting . got):" (cons e v))))=20 > > (define (sleep-loop) > (expect #:need-to-sleep (atomic-box-ref state)) > > (dump "R: Going to (sleep 1)~%") > (atomic-box-set! state #:accepted) >=20=20=20 > ; SOMETHING WRONG IS HERE > (system* "sleep" "1s") > ; (sleep 1) > > (let ((v (atomic-box-compare-and-swap! state #:accepted #:nothing-to-do= ))) > (when (not (eq? #:accepted v)) > (dump "S: Repeating sleep~%") > (sleep-loop))) > > (dump "R: sleep-loop finished~%")) > > (define (main-loop) > (define (run-thread) > (dump "M: new sleep thread~%") > (atomic-box-set! state #:need-to-sleep) > (call-with-new-thread sleep-loop))=20 > > (dump "M: (sleep 3)~%") > (sleep 3) > > (dump "M: protocol exchange~%") > (let ((st (atomic-box-ref state))) > (case st=20 > ((#:nothing-to-do) (run-thread)) > ((#:accepted) (let ((v (atomic-box-compare-and-swap! state #:accept= ed #:need-to-sleep))) > (when (not (eq? #:accepted v)) > (expect #:accepted v) > (run-thread)))) > (else (expect #:need-to-sleep st)))) > > (main-loop)) > > (main-loop)