Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126682 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 7D6D71A00BC for ; Sun, 9 Mar 2025 22:05:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1741557750; bh=X3GuCbhuhOwtRXwJDULX678HZMpBOx37WYRBXHp3GJQ=; h=Date:From:To:In-Reply-To:References:Subject:From; b=T6YZTyA/gZgc1CDhZaShSWyLiY9Wfjo3YEVPfl+1EYJr3w6AK10u/sihErWTEy5u2 O3iI1cn2YA9nk+Gfo0iWDOi5WFfjuZf6yThLvRgQLzv1qikf1eUTHYxoEjerZSqH2O kfAqRS+arEqHVWuC2zZuhURQd33EYjB3+W13G2JQIAhflLGBTb91D8Pkwfc7N8QF9F kZqiO4YCCqR2rOgTArxRFVRFTBAhkKk6WWtQoCFMGhvG3BVrC4o+cD9PUSXJrRmO9t OEVndX+NsK7s54krvD2s5253tGoFpVRP4U7xEkHx62Vx4xgNbSfl2wNvHt3KW1SaoN oXxtxs069u9Mw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 96F62180071 for ; Sun, 9 Mar 2025 22:02:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fhigh-b5-smtp.messagingengine.com (fhigh-b5-smtp.messagingengine.com [202.12.124.156]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 9 Mar 2025 22:02:29 +0000 (UTC) Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfhigh.stl.internal (Postfix) with ESMTP id 21245254013A for ; Sun, 9 Mar 2025 18:05:03 -0400 (EDT) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-11.internal (MEProxy); Sun, 09 Mar 2025 18:05:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1741557902; x=1741644302; bh=X3GuCbhuhO wtRXwJDULX678HZMpBOx37WYRBXHp3GJQ=; b=T4KtMPLZ94gX3UX5pDs6Kdzjr6 4IZObYRyv0DCRv/HdxMNeIqMmvfWs5OrEJniDJxOLYGj6UW5YQSN+sa9Pdy2xZdf 6SY9u3c5G8Bv4m12rblcIvhKCS8y2fPRMb9Xr0ODF+ahpgd2ogcSGTCRhflD4PCe IS7GtI1M2NFIp9OKYLd/cjk2CWueBSCYAo1VjLziheZjvMH4apAqt3KX4UYcyVrF c+Aykx/QxPBkJrZ0YIvJPbplFvQQx4x9RLN4FDUxKBWoi/nn+7iVRWBu5yLVyd5p +Mm4B8xrRC8YdqDccwXvR8TVD1Sar0RTRT6mJECKQSLcO3/54zEc3llHSI5g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1741557902; x=1741644302; bh=X3GuCbhuhOwtRXwJDULX678HZMpBOx37WYR BXHp3GJQ=; b=eaKckMlgN8QtHT/S7LgdlmPhF26TWi0LRZYdmpkzLO5xOtfCWn1 yq4Y3Yw8Z3r2JHK+kztyJjrChJl7FslseDDftxD4Q67JD/SToGuJzneY+S7KICI6 XfWM7UV40D/Ld1mC09XyZNUsrWSHRfnI/nedcUdDgKARKGyi1hGlVq9MMYuq8aTL ZMzlX51MMfx/3mTtgU67sWm3bRbt2QCxqwL78wrybAS1bLrPCMkpC9PFSCHYk1jX p3eaKX2CGvCCqcjp8YFK8hzW/STiKyJ/kMyo7t9qiT0AlDsPCGgpkdTsIDp6ijOw AEVFpiUTwrKxXM5/2FJo/WATAR33EWcQO4A== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduudejiedtucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefogg ffhffvkfgjfhfutgesrgdtreerredtjeenucfhrhhomhepfdftohgsucfnrghnuggvrhhs fdcuoehrohgssegsohhtthhlvggurdgtohguvghsqeenucggtffrrghtthgvrhhnpeeivd dvudfggedvjefhffffteetkeevkeeiieelteeggefhheevkefhfeffueefhfenucffohhm rghinhepmhgrnhihsghuthhfihhnihhtvgdrtghomhenucevlhhushhtvghrufhiiigvpe dtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehrohgssegsohhtthhlvggurdgtohguvghs pdhnsggprhgtphhtthhopedupdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehinh htvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 83407780068; Sun, 9 Mar 2025 18:05:02 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Sun, 09 Mar 2025 23:04:40 +0100 To: internals@lists.php.net Message-ID: <4305eda7-0fa7-4dd4-a7ff-131cf1c82e51@app.fastmail.com> In-Reply-To: References: <1b6a5b3b-be9b-4e46-9cc6-b8b7f57b8494@app.fastmail.com> Subject: Re: [PHP-DEV] Re: PHP True Async RFC Content-Type: multipart/alternative; boundary=f70ec8ad9be54116aaa1f9c976687fa8 From: rob@bottled.codes ("Rob Landers") --f70ec8ad9be54116aaa1f9c976687fa8 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Sun, Mar 9, 2025, at 14:17, Rowan Tommins [IMSoP] wrote: > On 08/03/2025 20:22, Edmond Dantes wrote: > > > > For coroutines to work, a Scheduler must be started. There can be on= ly=20 > > one Scheduler per OS thread. That means creating a new async task do= es=20 > > not create a new Scheduler. > > > > Apparently, async {} in the examples above is the entry point for th= e=20 > > Scheduler. > > >=20 > I've been pondering this, and I think talking about "starting" or=20 > "initialising" the Scheduler is slightly misleading, because it implie= s=20 > that the Scheduler is something that "happens over there". >=20 > It sounds like we'd be writing this: >=20 > // No scheduler running, this is probably an error > Async\runOnScheduler( something(...) ); >=20 > Async\startScheduler(); > // Great, now it's running... >=20 > Async\runonScheduler( something(...) ); >=20 > // If we can start it, we can stop it I guess? > Async\stopScheduler(); >=20 >=20 > But that's not we're talking about. As the RFC says: >=20 > > Once the Scheduler is activated, it will take control of the=20 > Null-Fiber context, and execution within it will pause until all Fiber= s,=20 > all microtasks, and all event loop events have been processed. >=20 > The actual flow in the RFC is like this: >=20 > // This is queued somewhere special, ready for a scheduler to pick it = up=20 > later > Async\enqueueForScheduler( something(...) ); >=20 > // Only now does anything actually run > Async\runSchedulerUntilQueueEmpty(); > // At this point, the scheduler isn't running any more >=20 > // If we add to the queue now, it won't run unless we run another sche= duler > Async\enqueueForScheduler( something(...) ); >=20 >=20 > Pondering this, I think one of the things we've been missing is what=20 > Unix[-like] systems call "process 0". I'm not an expert, so may get=20 > details wrong, but my understanding is that if you had a single-taskin= g=20 > OS, and used it to bootstrap a Unix[-like] system, it would look=20 > something like this: >=20 > 1. You would replace the currently running single process with the new=20 > kernel / scheduler process > 2. That scheduler would always start with exactly one process in the=20 > queue, traditionally called "init" > 3. The scheduler would hand control to process 0 (because it's the onl= y=20 > thing in the queue), and that process would be responsible for startin= g=20 > all the other processes in the system: TTYs and login prompts, network=20 > daemons, etc Slightly off-topic, but you may find the following article interesting: = https://manybutfinite.com/post/kernel-boot-process/ It's a bit old, but probably still relevant for the most part. At least = for x86. =E2=80=94 Rob --f70ec8ad9be54116aaa1f9c976687fa8 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Sun, Mar 9, = 2025, at 14:17, Rowan Tommins [IMSoP] wrote:
On 08/03/2025 20:22, Edmond Dantes wrot= e:
>
> For coroutines to work, a Sched= uler must be started. There can be only 
> one Sch= eduler per OS thread. That means creating a new async task does 
> not create a new Scheduler.
>
> Apparently, async {} in the examples above is the entry point= for the 
> Scheduler.
>

I've been pondering this, and I think talking about= "starting" or 
"initialising" the Scheduler is sligh= tly misleading, because it implies 
that the Schedule= r is something that "happens over there".

I= t sounds like we'd be writing this:

// No s= cheduler running, this is probably an error
Async\runOnSch= eduler( something(...) );

Async\startSchedu= ler();
// Great, now it's running...

Async\runonScheduler( something(...) );

=
// If we can start it, we can stop it I guess?
Async\= stopScheduler();


But that's = not we're talking about. As the RFC says:

&= gt; Once the Scheduler is activated, it will take control of the 
Null-Fiber context, and execution within it will pause unti= l all Fibers, 
all microtasks, and all event loop eve= nts have been processed.

The actual flow in= the RFC is like this:

// This is queued so= mewhere special, ready for a scheduler to pick it up 
later
Async\enqueueForScheduler( something(...) );

// Only now does anything actually run
<= div>Async\runSchedulerUntilQueueEmpty();
// At this point,= the scheduler isn't running any more

// If= we add to the queue now, it won't run unless we run another scheduler
Async\enqueueForScheduler( something(...) );
=

Pondering this, I think one of the things = we've been missing is what 
Unix[-like] systems call = "process 0". I'm not an expert, so may get 
details w= rong, but my understanding is that if you had a single-tasking 
=
OS, and used it to bootstrap a Unix[-like] system, it would l= ook 
something like this:

1. You would replace the currently running single process with the new=  
kernel / scheduler process
2. That sc= heduler would always start with exactly one process in the 
queue, traditionally called "init"
3. The scheduler= would hand control to process 0 (because it's the only 
<= div>thing in the queue), and that process would be responsible for start= ing 
all the other processes in the system: TTYs and = login prompts, network 
daemons, etc

Slightly off-topic, but you may find the follo= wing article interesting: https://manybutfinite.com/post/kernel-boot-proces= s/

It's a bit old, but probably still r= elevant for the most part. At least for x86.

=E2=80=94 Rob
--f70ec8ad9be54116aaa1f9c976687fa8--