From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Akira Kyle Newsgroups: gmane.emacs.devel Subject: Re: "Asynchronous Requests from Emacs Dynamic Modules" Date: Sat, 31 Oct 2020 13:25:58 -0600 Message-ID: <86ft5ufb95.fsf@akirakyle.com> References: <86imarfldb.fsf@akirakyle.com> <86y2jn9j70.fsf@163.com> <83pn4y96ut.fsf@gnu.org> <83lffmhi5y.fsf@gnu.org> <83h7qahe03.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; format=flowed Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15991"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.4.13; emacs 28.0.50 Cc: Philipp Stephani , emacs-devel@gnu.org, yyoncho , Stefan Monnier , all_but_last@163.com To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Oct 31 20:26:55 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kYwWd-00043F-9T for ged-emacs-devel@m.gmane-mx.org; Sat, 31 Oct 2020 20:26:55 +0100 Original-Received: from localhost ([::1]:49382 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kYwWc-0006Aj-Bj for ged-emacs-devel@m.gmane-mx.org; Sat, 31 Oct 2020 15:26:54 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46950) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kYwVm-0005iM-Rk for emacs-devel@gnu.org; Sat, 31 Oct 2020 15:26:02 -0400 Original-Received: from mail-io1-f50.google.com ([209.85.166.50]:43636) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kYwVl-0000rD-5s; Sat, 31 Oct 2020 15:26:02 -0400 Original-Received: by mail-io1-f50.google.com with SMTP id h21so10987527iob.10; Sat, 31 Oct 2020 12:26:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject :in-reply-to:date:message-id:mime-version; bh=YlYPzLTzm3aslLKoRGs9HrQ/h3C31CEg03Q15uzlTzg=; b=DgT5e4QsEfojNIB0Ko7LGQpUG9rrNB00skfvky3L2KxNAW1xYKDdGHEbnRx+Uhzy5+ EYmop9kLr2wqBgeaaXmlz1YiePWrfxfRWWsMxTdxJKZRc0kG8DkhtL0S26mNmFQlnAYX 1KtY0gyVQJ8sDf6YGLHnbW/j273yy8AAiOeNwUPJpveT+r/GQunUEFQC96dNy1tn/dAU DAvaLTtFLozqpccdBzA1dH6CgksV1xM96miNrvSBw8W8WybgaVIWQqweQKk4MYWLvZpZ NmC8VTI/YCyyHnUtGa0aK1LtDi1DjS/wMM3av+iX3jt4LvpXw/9S83YGcFZTuBEAZRpP uB5A== X-Gm-Message-State: AOAM5314MSiijkm8ZlYBHxjx1EETWWjKwAq0jPMEtByli/3Dl52ZW52m yURJVBAeben04eAWG0Bl0EQ= X-Google-Smtp-Source: ABdhPJwijBxQ4ydtxr73M4+8uC6Q7GgWn5eG6jOr3z/yCbbnQRQvBNkUi+2y30s2jJFs2KcD6klruA== X-Received: by 2002:a05:6602:d7:: with SMTP id z23mr6009056ioe.142.1604172359807; Sat, 31 Oct 2020 12:25:59 -0700 (PDT) Original-Received: from lore ([2601:281:8080:45f0:5594:5dba:fcba:b6e5]) by smtp.gmail.com with ESMTPSA id o124sm7666417ila.62.2020.10.31.12.25.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 31 Oct 2020 12:25:59 -0700 (PDT) In-reply-to: <83h7qahe03.fsf@gnu.org> Received-SPF: pass client-ip=209.85.166.50; envelope-from=aikokyle@gmail.com; helo=mail-io1-f50.google.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/31 15:26:00 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:258587 Archived-At: On Sat, Oct 31, 2020 at 04:43 AM, Eli Zaretskii wrote: >> That is unfortunate. I was assuming that at least thread >> primitives can be made thread-safe. > > They are thread-safe, but they rely on strict discipline of > having > one, and only one, Lisp thread active at any given time. IOW, > the > mechanism that switches threads is not "thread-safe". To summarize so far, I see three different ways of tackling this: 1) Chris Wellon's solution in the article I linked using the SIGUSR1 signal which Emacs handles in the event queue notify the running Lisp Thread that it should call back into module functions. This idea could be expanded to allow modules to define their own events and lisp handlers that will respond to them. 2) Stefan's and Philipp's proposal of using the process interface with file descriptors to pipes and perhaps `process-filter` to notify the Lisp Thread that it should call back into the module functions. 3) yyoncho's proposal to use the lisp threading interface, specifically condition variables to allow dynamic modules to `condition-notify`. I see advantages and disadvantages to each. I think the most natural solution would be a dynamic module interface that allows grabbing and releasing Lisp's global thread lock. I think this would simplify writing dynamic module functions which could potentially cause Emacs to hang as it wouldn't require module authors to think about the lisp machinery to figure out what module function with what state to call back into when it needs to get its result back into lisp land. The way such an interface is implemented could be with any of the above mechanisms or something else.