From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stephen Leake Newsgroups: gmane.emacs.devel Subject: elisp test-and-set? Date: Fri, 25 May 2018 16:00:04 -0500 Message-ID: <86po1jv4bv.fsf@stephe-leake.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1527281975 23923 195.159.176.226 (25 May 2018 20:59:35 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 25 May 2018 20:59:35 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (windows-nt) To: emacs-devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri May 25 22:59:31 2018 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 1fMJo8-00062w-F6 for ged-emacs-devel@m.gmane.org; Fri, 25 May 2018 22:59:28 +0200 Original-Received: from localhost ([::1]:46678 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fMJqF-0006xV-JI for ged-emacs-devel@m.gmane.org; Fri, 25 May 2018 17:01:39 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57399) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fMJp7-0006w3-9Q for emacs-devel@gnu.org; Fri, 25 May 2018 17:00:30 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fMJp2-0001KJ-Cp for emacs-devel@gnu.org; Fri, 25 May 2018 17:00:29 -0400 Original-Received: from smtp105.ord1d.emailsrvr.com ([184.106.54.105]:43580) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fMJop-00013R-P2 for emacs-devel@gnu.org; Fri, 25 May 2018 17:00:24 -0400 Original-Received: from smtp22.relay.ord1d.emailsrvr.com (localhost [127.0.0.1]) by smtp22.relay.ord1d.emailsrvr.com (SMTP Server) with ESMTP id A75F2E023F for ; Fri, 25 May 2018 17:00:07 -0400 (EDT) X-Auth-ID: board-president@tomahawk-creek-hoa.com Original-Received: by smtp22.relay.ord1d.emailsrvr.com (Authenticated sender: board-president-AT-tomahawk-creek-hoa.com) with ESMTPSA id 728DEE0341 for ; Fri, 25 May 2018 17:00:07 -0400 (EDT) X-Sender-Id: board-president@tomahawk-creek-hoa.com Original-Received: from Takver4 (76-218-37-33.lightspeed.kscymo.sbcglobal.net [76.218.37.33]) (using TLSv1.2 with cipher AES256-GCM-SHA384) by 0.0.0.0:25 (trex/5.7.12); Fri, 25 May 2018 17:00:07 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 184.106.54.105 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:225726 Archived-At: In ada-mode, I'm using a parser running in an external process to compute faces and indentation. Since faces are computed by font-lock, which runs on a timer in the background, it can try to run when indent is running in the foreground. So in the code that deals with the external process, I need mutual exclusion; prevent font-lock from starting a new parse if a parse is already running. The code I currently have for that is: (if (wisi-process--parser-busy parser) (error "%s parse abandoned; parser busy" wisi--parse-action) (setf (wisi-process--parser-busy parser) t) ... more parsing stuff ) There is a tiny window of time when this can fail; if font-lock and foreground both execute the "if" condition 'simultaneously' (ie, before the other sets busy t), both will go on to parse. In other contexts I'd use a "test and set" instruction for this; read the flag and set it true in one uninterruptible action. I don't see anything like that in elisp, and searching in the elisp manual for "mutual" and "exclusion" is no help. I also don't see "font-lock-inhibit", which could be useful here, but would probably have the same race condition. Is there a way to do this right? -- -- Stephe