From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Noam Postavsky Newsgroups: gmane.emacs.devel Subject: Re: semantics of thread-signal (WAS: Crashing the new thread code) Date: Sun, 11 Dec 2016 19:16:35 -0500 Message-ID: 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 1481501896 29711 195.159.176.226 (12 Dec 2016 00:18:16 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 12 Dec 2016 00:18:16 +0000 (UTC) Cc: Emacs developers To: Juliusz Chroboczek Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Dec 12 01:18:13 2016 Return-path: Envelope-to: ged-emacs-devel@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 1cGEJo-0006sN-Tm for ged-emacs-devel@m.gmane.org; Mon, 12 Dec 2016 01:18:13 +0100 Original-Received: from localhost ([::1]:57684 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cGEJt-0001TN-55 for ged-emacs-devel@m.gmane.org; Sun, 11 Dec 2016 19:18:17 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34704) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cGEJI-0001TF-Nv for emacs-devel@gnu.org; Sun, 11 Dec 2016 19:17:45 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cGEJE-0007Y3-F6 for emacs-devel@gnu.org; Sun, 11 Dec 2016 19:17:40 -0500 Original-Received: from mail-oi0-f53.google.com ([209.85.218.53]:32917) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cGEJE-0007Xp-9I for emacs-devel@gnu.org; Sun, 11 Dec 2016 19:17:36 -0500 Original-Received: by mail-oi0-f53.google.com with SMTP id w63so72883661oiw.0 for ; Sun, 11 Dec 2016 16:17:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:from:date:message-id:subject:to:cc :content-transfer-encoding; bh=l+DKAgf1dvssq/o1HSMsFcugbAsY1sP0zzS1Hj5ghIY=; b=SZV1EIZbRKjhoVav/twmKnGhvrJ1IaDbp4Es6tsDHT/tt1YstCe1uktFZrLpIcvR7B DjpS2KxjPvoqqM+daBiuyjlodAhVOjueMciVc5HBtyGeTealCAkVaaEIzzAPweVeJkJy fhLQ9rYET2G2q/1MdDT2MCCXXB0h2kvGkUcC5/rvNrl3m7xHswdABsWzlqbtaAP+wlxe 6VYPgcdu90dJhK62hf1XPps0wzdhTPHY1eTWtV4Gf9v/zQNZE+AEuBFpY2sPEj6ke2lw okHnl9oMfNunSncahwszIHkXnsi5qF4GQ8xmT05p+Z8bkgV3K9zbfA+kk335LXSXgSne 59EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:from:date:message-id:subject :to:cc:content-transfer-encoding; bh=l+DKAgf1dvssq/o1HSMsFcugbAsY1sP0zzS1Hj5ghIY=; b=bZBFeHEC5gTXwaiA32DNUIfex8WD99RuHt2JnziuQdQN/hnpGByZ7Qs8kKJpUg5GTP ECb91vKYccZFSQ4B+jakA4+CMFk2oaCtQZwF5MaBckU2G4jWxHexLSz6+6lbOoOcoWd3 D9CuY6U3qWL6bRrqkpYIpR4IwvOIIbRaUKR5TJVXJOdh6xMwEeNzui99v4S/0CoChuRl f+1nqwFra2CSu2Cu8r5xJ7Ylha6i+VpYhrjFujzDMEO3KR+u809Y0mzaZUG774xHwtlv szrH6KoCjYxp67nZUuz5C5iRmTjeeOgRbCWifqMVBojf5E48ir13lWAhny0clwzGltGc 6bcQ== X-Gm-Message-State: AKaTC02p86wSg8s4regoxOkSpTVo6JJAT7GwdwYGGRXSAr3GUGCP3yCHKXIaePfZDU0+fw8gZn7xAJ4cls2a1w== X-Received: by 10.157.58.119 with SMTP id j110mr47643310otc.208.1481501795427; Sun, 11 Dec 2016 16:16:35 -0800 (PST) Original-Received: by 10.157.6.234 with HTTP; Sun, 11 Dec 2016 16:16:35 -0800 (PST) X-Google-Sender-Auth: yVXZ_y8cNfsHkfs7xbl2AfK68GM X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.218.53 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:210318 Archived-At: On Sun, Dec 11, 2016 at 5:56 PM, Juliusz Chroboczek wrote: >> I would expect the thread to receive the signal as soon as it starts >> running again. > > I'm not sure what the semantics of signal-thread is supposed to be. I'm not sure either, my expectations are shaped by experience with non-Emacs thread code. > The manual says: > > =E2=80=98thread-signal=E2=80=99 will cause a thread to exit a call to= =E2=80=98mutex-lock=E2=80=99, > =E2=80=98condition-wait=E2=80=99, or =E2=80=98thread-join=E2=80=99. > > I assumed this to mean that the condition will only be delivered when > one of these functions is called, but your comment seems to imply that > it's meant to deliver the condition as soon as possible. My interpretation is that mutex-lock (and the others) block the thread until something happens (e.g., another thread calls mutex-unlock), and thread-signal is another thing which can end the blocking (and also trigger a signal when the thread next runs). > > Which makes sense, but gives a whole new flavour to using unwind-protect > now that conditions can be signalled asynchronously. > > (Aside: I'm actually not quite sure in that case that unwind-protect can > be used safely at all. What happens if a condition is signalled during > the cleanup? Say: > > (let ((foo nil)) > (unwind-protect > (progn > (setq foo (make-foo)) > (do-stuff-with foo)) > (when foo (destroy-foo foo)))) > > if a condition is signalled just before the cleanup but after exiting > the body, will we leak a foo? End of aside.) This can't happen, because thread are cooperative. i.e., only one thread runs at a time.