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: "Asynchronous Requests from Emacs Dynamic Modules" Date: Fri, 30 Oct 2020 15:35:12 -0600 Message-ID: <86imarfldb.fsf@akirakyle.com> 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="22826"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.4.13; emacs 28.0.50 To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Oct 30 22:36:10 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 1kYc48-0005bF-5W for ged-emacs-devel@m.gmane-mx.org; Fri, 30 Oct 2020 22:36:08 +0100 Original-Received: from localhost ([::1]:44748 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kYc47-00084A-7U for ged-emacs-devel@m.gmane-mx.org; Fri, 30 Oct 2020 17:36:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37904) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kYc3J-0007XY-V9 for emacs-devel@gnu.org; Fri, 30 Oct 2020 17:35:17 -0400 Original-Received: from mail-il1-f180.google.com ([209.85.166.180]:33871) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kYc3H-00085l-M3 for emacs-devel@gnu.org; Fri, 30 Oct 2020 17:35:17 -0400 Original-Received: by mail-il1-f180.google.com with SMTP id v18so7774559ilg.1 for ; Fri, 30 Oct 2020 14:35:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:user-agent:from:to:subject:date:message-id :mime-version; bh=zvu1yNY3p/YHtAdc6sGGTTIor7OkYGB12eReUU0gTUM=; b=tjBzxEnPaHZjIiHXdztmc+2Eb2z9wVtuhh1UtdOiOX0cyk10hoDWTxHtz8wK0eVF4H c/QL97eJauJNyQ2+Mz7b4LbLXl00cG++ugSsDj+RKG3CA60B3uk1LfLVZOKqrXrZeyuQ UQOp3YJ00YZrVHHzdCJRA0xiYD7fsDHqDfDJfY0tfWt4xjLZoyUXE5IK5M1z8zjwIQVb hZJN3fFA8z6flJ6DATtavTLWS94zvFLYV8790jc6KAItiA01XlAg743rDfUDIULlAQoj 55iA3fidS/ICT7RSPhrp88iUK3OmqUKENOEDKHPfmX9CRRZTegpxzLEjGGWvyJZ3oELv 8D0w== X-Gm-Message-State: AOAM530B/PwnuZXIztoZ2lN+LWbOfwuPXMia3ToGzu1vJHcYFE7XWQVY EIHrBElRuz56N/pbrO29cJvOU8fedCY= X-Google-Smtp-Source: ABdhPJx3W9m/h/6XNZV2hmdymcbh22R0EPWalYAX+cfNVZumNgEQosv4JuFfdTE8c/2zKZfIgqNdTw== X-Received: by 2002:a05:6e02:4ad:: with SMTP id e13mr3053549ils.59.1604093713956; Fri, 30 Oct 2020 14:35:13 -0700 (PDT) Original-Received: from lore ([2601:281:8080:45f0:66ce:e796:bc0b:bebb]) by smtp.gmail.com with ESMTPSA id x5sm5692103ilc.15.2020.10.30.14.35.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 14:35:13 -0700 (PDT) Received-SPF: pass client-ip=209.85.166.180; envelope-from=aikokyle@gmail.com; helo=mail-il1-f180.google.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/30 17:35:14 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.25, 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:258564 Archived-At: I'm trying to use Emacs' Dynamic Modules in an asynchronous setting where C module functions run in a separate thread from Emacs' main thread which is responsible for calling into the module functions. The natural problem then is how to notify Emacs when one wants to retrieve the result of the asynchronous operation from some lisp. Since the module docs explicitly say that module functions "may only interact with Emacs from Lisp interpreter threads (including the main thread) created by Emacs", it is not possible then for a separate module thread to interact with Emacs in an unprompted way through the module interface [1]. This blog post [2] has a solution to this problem by sending SIGUSR1 to Emacs, but that feels a bit hackish and forces one to do more work to manage all the different possible module threads and events that one may want to signal to Emacs. I suppose one could also conceivably also use Emacs' dbus support but that still feels clunky. Maybe its possible it's possible to use Emacs lisp's threads [2] to solve this but it's not clear to me how to go about doing so and I haven't found anyone that has done so. Does anyone know of the best way to handle this? Perhaps the module interface should be expanded to handle this situation? [1] https://www.gnu.org/software/emacs/manual/html_node/elisp/Module-Functions.html#Module-Functions [2] https://www.gnu.org/software/emacs/manual/html_node/elisp/Threads.html#Threads [3] https://nullprogram.com/blog/2017/02/14/