From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Philipp Stephani Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Support threads in modules Date: Sat, 22 Apr 2017 20:05:19 +0000 Message-ID: References: <20170422152444.48735-1-phst@google.com> <83zif8p8d3.fsf@gnu.org> <83tw5gp6hy.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a114b33e4560d60054dc6e5f4 X-Trace: blaine.gmane.org 1492891580 2741 195.159.176.226 (22 Apr 2017 20:06:20 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 22 Apr 2017 20:06:20 +0000 (UTC) Cc: phst@google.com, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Apr 22 22:06:15 2017 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 1d21IN-0000XC-9g for ged-emacs-devel@m.gmane.org; Sat, 22 Apr 2017 22:06:15 +0200 Original-Received: from localhost ([::1]:36718 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d21IO-0007hV-4f for ged-emacs-devel@m.gmane.org; Sat, 22 Apr 2017 16:06:16 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58596) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d21Hi-0007hE-EY for emacs-devel@gnu.org; Sat, 22 Apr 2017 16:05:35 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d21Hh-0006oh-6q for emacs-devel@gnu.org; Sat, 22 Apr 2017 16:05:34 -0400 Original-Received: from mail-wm0-x22a.google.com ([2a00:1450:400c:c09::22a]:35853) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d21Hf-0006oL-4h; Sat, 22 Apr 2017 16:05:31 -0400 Original-Received: by mail-wm0-x22a.google.com with SMTP id o81so36783624wmb.1; Sat, 22 Apr 2017 13:05:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=j4TbaCcExbyq5fkS7ux8iWFca7jGNcuwpXOALj70rNk=; b=u/Xw8qPt2Jol8GDH/gw1xxL30nZNoW+z/yMbEFZ5Mj56xBrcldZHqPffUGO0Tb1LpT kxUC0l0DN6N6ti/MW4sEh6VeCfUk9Ec276m5WqWLEwMxndzc5QffEjaKF9ybYL6Gx/jb oRAPvRjx2WpPtPf6qeC6imKZPwpIF2VU5ztO2vc+ZQoNR+uwIuG42LndHbQ4IfhRtS11 5oBK6jw7FrsmpLPts8s+qDhBSIgsw3wMNGLHbYF52v54FZFXy87Z1fq7vx04sS0NXz6g JPQuxx6Do92KfF0zCFnNrll5Vkk9AJZZwkDd+MR7vhVv5dsPWQ0b+pZfFfJVGNRqVL0X N7lQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=j4TbaCcExbyq5fkS7ux8iWFca7jGNcuwpXOALj70rNk=; b=MKPO/b2LF4IQHFFgmdnPRCdrvLaIXZsOHxMoxR7453Vcylt/7JQH5sEodea+pANtHo gEwTX3SrG2yt882DcIHaiT2Bog8jK15OQwT+W0uWpwIWig9D/YHvG+Zois3K2sMCp+eo pPAKAEHUbkgn7t9cV2yyVhZwe10SIyf1I1bf8fo+F2g7oyhR+9v9AWgnl4eqogNR6qEK lJ1tX++vkn6rgGh47goqwC9MIxQBKNTl3tfLuic4UBMjO0fktDDQk2l2bI4f3Od0hOgX wV8kltxaXkc9Cf9TFxjvHx1gKk3KvRoRVjw/sPy7lYOvH2deBaFvGhuD5RDWhTiimlUl DLpw== X-Gm-Message-State: AN3rC/47943Z3wkTKDPSKx+bov6I5pxWLh9BAQ5fTpMYlxs+8ObH1wry bBcCIrp1S8WDWeMtiXHJRRdPBfAOCg== X-Received: by 10.28.150.86 with SMTP id y83mr3948246wmd.46.1492891530035; Sat, 22 Apr 2017 13:05:30 -0700 (PDT) In-Reply-To: <83tw5gp6hy.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::22a 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:214225 Archived-At: --001a114b33e4560d60054dc6e5f4 Content-Type: text/plain; charset=UTF-8 Eli Zaretskii schrieb am Sa., 22. Apr. 2017 um 21:49 Uhr: > > From: Philipp Stephani > > Date: Sat, 22 Apr 2017 19:21:35 +0000 > > Cc: emacs-devel@gnu.org, phst@google.com > > > > Can you explain the purpose of these changes and the motivation? A > > module shouldn't be restricted to be used by a single thread, should > > it? > > > > No, but the thread used to create an environment object, the current > Emacs thread, and the current OS thread > > all have to match. Right now this isn't checked; the current code checks > only for the main thread, which isn't > > correct any more now that there can be more than one interpreter thread. > > I agree that checking for the main thread is not TRT, but why not > allow any thread of those in all_threads? Why do we care that the env > pointer was created by the same thread as the one using it? We should > only care that the invoking thread is one of the Emacs application > threads, no? > - Using objects across threads requires careful synchronization. It's not impossible, but a large burden on module authors. - The more restrictive the module API is, the more freedom we have in the implementation. - The current check is easy to implement and understand. A check for multiple threads would require another hash table with thread IDs etc. - The Emacs module API is modelled after JNI, which has the same restriction ( http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/design.html). We should stick to the JNI semantics wherever possible, because JNI is a well-tested and robust technology. --001a114b33e4560d60054dc6e5f4 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


Eli Za= retskii <eliz@gnu.org> schrieb am= Sa., 22. Apr. 2017 um 21:49=C2=A0Uhr:
> From: Philipp Stephani <p.stephani2@gmail.com>
> Date: Sat, 22 Apr 2017 19:21:35 +0000
> Cc: emacs-dev= el@gnu.org, phst@g= oogle.com
>
>=C2=A0 Can you explain the purpose of these changes and the motivation?= A
>=C2=A0 module shouldn't be restricted to be used by a single thread= , should
>=C2=A0 it?
>
> No, but the thread used to create an environment object, the current E= macs thread, and the current OS thread
> all have to match. Right now this isn't checked; the current code = checks only for the main thread, which isn't
> correct any more now that there can be more than one interpreter threa= d.

I agree that checking for the main thread is not TRT, but why not
allow any thread of those in all_threads?=C2=A0 Why do we care that the env=
pointer was created by the same thread as the one using it?=C2=A0 We should=
only care that the invoking thread is one of the Emacs application
threads, no?

- Using objects across thr= eads requires careful synchronization. It's not impossible, but a large= burden on module authors.
- The more restrictive the module API = is, the more freedom we have in the implementation.
- The current= check is easy to implement and understand. A check for multiple threads wo= uld require another hash table with thread IDs etc.
- The Emacs m= odule API is modelled after JNI, which has the same restriction (