From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: zhanghj Newsgroups: gmane.emacs.devel Subject: Re: Emacs design and architecture. How about copy-on-write? Date: Thu, 21 Sep 2023 04:51:13 +0800 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="------------GCjywbevdpeQbaTnQ50RBcdO" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31679"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 To: "emacs-devel@gnu.org" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Sep 20 22:57:19 2023 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 1qj4G6-00085V-Pz for ged-emacs-devel@m.gmane-mx.org; Wed, 20 Sep 2023 22:57:19 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qj4FP-0005SU-GH; Wed, 20 Sep 2023 16:56:35 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qj4FJ-0005RI-Ge for emacs-devel@gnu.org; Wed, 20 Sep 2023 16:56:29 -0400 Original-Received: from mail-os0jpn01olkn20812.outbound.protection.outlook.com ([2a01:111:f403:700c::812] helo=JPN01-OS0-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qj4FH-0006JC-0E for emacs-devel@gnu.org; Wed, 20 Sep 2023 16:56:29 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YN7ADn7U74LD6g8fcnAWg9Clu0rA+kz0/0y2iANgkdkKHOxPpO8dn/IbxvHCAg2PwQYD5GAEUuHv0sqW0zXZ3pjLOOCYnDpVNy/0J1Gx1D6/fU102gDqGiBjX/doXJ15u02wGA8qHMrotrBXTz4Ybzi1B7Xn47ixOEW50XGo0oTq4jLCrPbU8/bk6oNjwJ4EouV/5H8+yoGUgi9oT6tEdKvdyK8LYyVIZz7CtiRFC7rrn8TumZHPCa/09jMip2Qyk6/jraNE3WV8f+3oHcBPlfmMts2pw1LO+goZpT3m1Nze/1TPYyf36oAcC5mHhVTM9TcmyxBZzXPJm9rMM33TJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ejmtyLdFaLbVGSabMnp1u32dU0nGau8FmG0fZkKDmM0=; b=JWX6L7t0uGDqL4Rf3I5PdKekG/ssmv78Zz16QZjZHpoVLEL96q4P/3RVT6YT5GR4fHJk3lgwZHG/fcKitYUvBl1HYxVrRYBWebysgyI50cur/qYKyWUAwtviT2raTU4YPW/tCD+S4jJ31NVRcWaTsSX43yeuaxta/colYnbOfPAT6QPTgSeQbMfh1Zfs4fEH9EhZ/3m77LWfn6YgKI1BWW4IyKv/gzwqoLKX9ve+DSBcIIq6P74nl+qLNTDJPeaHdfJvploAcl0KZhMSBoU+fOaBvXk1go5v1InFxAyuqj/S7FifFGRNTKE2A0aVWjlEMniNBErcmNLDbhNLRaqXCA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ejmtyLdFaLbVGSabMnp1u32dU0nGau8FmG0fZkKDmM0=; b=qG7HG2bsMSKj0+i6I8IwVkHphlQhAbuWm9948ARZGbkfW6RvZ6ExY8VkOYQl4jnVzeAAEd+bkeXNRe6KzJ5EgA9o7j+oK7an19Tdp5lneW+HwKatqD4257KffT0f/OykTkcOlhZjDSlONDkmadNyN5XpAleTs6x4kLohOHp93syAX0VU2uGxBFw9qVzMlytgg+nASQoj4WjxSKu6ng8pIfD9llcchqgxHxh5jIebFBYkWUMsZRsXWJmBeBgnumtfJc1dRluOQyT6jg6gquOASvuyGP/atx3nU1IduvwqvxLjipqi95zJm5z/s+VYcIr9gbvkEicbX6wwGSkX4VFLzw== Original-Received: from TYCP286MB2210.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:154::14) by TYWP286MB3665.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:3f7::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.10; Wed, 20 Sep 2023 20:51:19 +0000 Original-Received: from TYCP286MB2210.JPNP286.PROD.OUTLOOK.COM ([fe80::651:23f9:414c:12]) by TYCP286MB2210.JPNP286.PROD.OUTLOOK.COM ([fe80::651:23f9:414c:12%3]) with mapi id 15.20.6813.018; Wed, 20 Sep 2023 20:51:19 +0000 Content-Language: en-US X-TMN: [d7MJ7U9vGmuj8xN+Dnk9UCuzKplRIzo/] X-ClientProxiedBy: SG2PR01CA0195.apcprd01.prod.exchangelabs.com (2603:1096:4:189::17) To TYCP286MB2210.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:154::14) X-Microsoft-Original-Message-ID: <2e3004db-6b0c-563f-2476-6053957436a7@outlook.com> X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYCP286MB2210:EE_|TYWP286MB3665:EE_ X-MS-Office365-Filtering-Correlation-Id: fcc2de98-0760-4531-0e19-08dbba1b5731 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Kza+OXfwRKCqiWlLiyaZdR1nq2G8mCUzF4T0o5mH0MjfnqnOL7TyvIEOy8K+66i4MXaB7DXz5RMNJh8KtBJCsPtHIeU2J4mDmK0PZksN0F/Ht1XxJklenBoTLtev2oFtSeF4Bu2k/v9e54BHMoFaOBKNT1vsPWACcITE9G2P9tpqy/vhgtXc4QtLC+dygKVrKOom1bbIT26yWqCuiH44h+08x6uVPe19jGbiPrBV3YBbZ3bAwvz0wJes9CoTZhG1U2dPXcsiVbAztWrwXMnGg333dPsimvUh4YbuiExjli/uZrID06RVRsW4YUVJUsw13Hz9PVN68DDfNxTDUIMMazIH2JH5+FNooNDKpOUIB/3CgPBE3HdSCq+XBPYdoSSKRpMK0t/bR8EXA2hGMe1kui52+zc+c+tVN2z0XE5VzX5Ib+aFIZtjZpz51YBVhuNZOtEXF582oaVWFhITwFBD6wdtbDaD7YSZ/EXxXUNYoBg6Qv0eqHZMpUHumAMq0Wnh0MD8PJI89oO1LGsix5ecsSnqChDLcSuUX9ORAWtkI8d5obChBsOIn66r9IJmHWn4 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?UXB0VlA2UEhCNUhXL2ZuQ1FwSHFEcndSZ3ZyalN1N0t4T2V0dEE3d3YwSWxJ?= =?utf-8?B?RDhLTGtuK21JaHAwNG96UmwxR1FpZnZWU3hnbkUycUYxTS9oUUR4SkdWNHE2?= =?utf-8?B?ei9zVjdsdUFWM0o0ZGJuWFJSdHVIUGZWQjJ0WndmcHRoQTJNZUI5U1RyMmZv?= =?utf-8?B?QzBNK3lWZXJhdVZTU2d1ZXJVMDFXU2ZYd2FnNmt5YTJRNWNmcTM3MUVWK2pB?= =?utf-8?B?ZTdJZnBqY3pmOG5vUU90SXRld1ZZRzV4Z013VVVwMitqQzFLUGdCRW1ITzFv?= =?utf-8?B?cWw1MFRTRm02UzFiWFhTRWRsYW9MYm40ZWtEUEtSMnEza0VEYzVNNWw0Q3Uv?= =?utf-8?B?ZEdCQ0NUVmJSVkZnNXN6NU5wWklROGtwYUx2NWFJVGNpaE1zaEp4VmRCb0Rp?= =?utf-8?B?N1VXdDl6SWViNjMzaDU3aDF4OUlWRFJjMC9zK2lyS0ZGa2xZOG1wWmFkejVD?= =?utf-8?B?dDNSTDFOOG12QXRjQ1FnSGsvWlpSTHNXeUl1eHZGRGV4cFF4ZXU1ekZPdDJT?= =?utf-8?B?eXRtM0dlQ29OcjkvZks0UTFOOEdjY1VpY2Z3UVVaRGVBSmlHQTdhSW44MWtU?= =?utf-8?B?a2M2aUgwRThUSEZVVjRoQVZvK0w1UncwVUZQaTc2KytKbVhhcUNKcEdBMk40?= =?utf-8?B?SkdOWWpnOVZ6eEtmdGhYN3RtNlBQUUJENytXdE X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: fcc2de98-0760-4531-0e19-08dbba1b5731 X-MS-Exchange-CrossTenant-AuthSource: TYCP286MB2210.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2023 20:51:19.5414 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYWP286MB3665 Received-SPF: pass client-ip=2a01:111:f403:700c::812; envelope-from=ccsmile2008@outlook.com; helo=JPN01-OS0-obe.outbound.protection.outlook.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FORGED_MUA_MOZILLA=2.309, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, SPF_HELO_PASS=-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.29 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-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:310854 Archived-At: --------------GCjywbevdpeQbaTnQ50RBcdO Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit The same will happen if only the main thread can display. If a non-main thread wants to prompt the user, it will have to wait until the main thread becomes available, prompts the user, and returns the response. Someone always has to wait when threads need to synchronize. There's no way around that. Doing this in the thread that needs to display/prompt is easier because the context and relevant variables don't need to be communicated to another thread. Sorry for my poor English. Message queue is a good solution for parallel and concurrence. I think it is not a good idea to let all threads to do display things directly. It will be better to let non-main threads to do display things via message queue, like many GUI toolkit does. It is also like the message loop in Emacs. This will make many things easier. For GUI toolkit on windows, there are two basic API: Sendmessage and PostMessage. Non-gui thread can use theme to do display and UI related things. For example in Emacs, when a non-main thread calls `message', a small display task is built and put into the message queue of the main thread, like `PostMessage` does. If it calls `read-file-name`, an UI task is built and put into the message queue of the main thread like `SendMessage` does, while the caller thread will be blocked until result comes. When all display jobs are all in one thread (decoupled with other threads), display jobs may be scheduled more efficiently and may be concurrent internally. --------------GCjywbevdpeQbaTnQ50RBcdO Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit
The same will happen if only the main thread can display.  If a
non-main thread wants to prompt the user, it will have to wait until
the main thread becomes available, prompts the user, and returns the
response.

Someone always has to wait when threads need to synchronize.  There's
no way around that.  Doing this in the thread that needs to
display/prompt is easier because the context and relevant variables
don't need to be communicated to another thread.

Sorry for my poor English.

Message queue is a good solution for parallel and concurrence.

I think it is not a good idea to let all threads to do display things directly. 
It will be better to let non-main threads to do display things via message queue,
like many GUI toolkit does. It is also like the message loop in Emacs. 
This will make many things easier. 

For GUI toolkit on windows, there are two basic API: Sendmessage and PostMessage.
Non-gui thread can use theme to do display and UI related things.

For example in Emacs, when a non-main thread calls `message', a small display task is built 
and put into the message queue of the main thread, like `PostMessage` does.
If it calls `read-file-name`, an UI task is built and put into the message queue of
the main thread like `SendMessage` does, while the caller thread will be blocked until result comes.

When all display jobs are all in one thread (decoupled with other threads), display jobs may be scheduled
more efficiently and may be concurrent internally.

--------------GCjywbevdpeQbaTnQ50RBcdO--