Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100481 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 15381 invoked from network); 9 Sep 2017 06:29:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Sep 2017 06:29:16 -0000 Authentication-Results: pb1.pair.com smtp.mail=hufeng1987@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=hufeng1987@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.66 as permitted sender) X-PHP-List-Original-Sender: hufeng1987@gmail.com X-Host-Fingerprint: 209.85.218.66 mail-oi0-f66.google.com Received: from [209.85.218.66] ([209.85.218.66:36335] helo=mail-oi0-f66.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C5/B4-10715-B3A83B95 for ; Sat, 09 Sep 2017 02:29:15 -0400 Received: by mail-oi0-f66.google.com with SMTP id g15so3068773oib.3 for ; Fri, 08 Sep 2017 23:29:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:message-id:in-reply-to:references:subject :mime-version; bh=BdN+zKWy1xFXFA9tHOULdkrEwhNtdyM1D+pUAmi7YGw=; b=ZkIRq5N8y1ejV5oi5k9yuoUkdrZUQEOxGFIXx4aljW6HQRWqq1+nt0rDz7dtLyHJWC CzUImUd9QSt7x90uKbPW9PiRD0uzHWus1wPVicJt633QVQN8fH1ubkg6liwvYk0IBSrZ +NkNb4tAPOKdCweQeRN8tKeQqBe5d8N4YbfS5Spuxu9cvcKY0Yerx8SLcG/o/fPybWDZ 3d/3LWTibmpwdvHifWG0Wqyawtt3e0uMAi//rzxz4LCyozyu4vUWRfpo+7N6aMbLAVjp OjbtQrCCaXnkXdGOBTbR51094fIc6Y9PB/Z3E6QKwHIvRR4uz+Dr1Ogjjz+sYBFgOcEl Aihw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:message-id:in-reply-to :references:subject:mime-version; bh=BdN+zKWy1xFXFA9tHOULdkrEwhNtdyM1D+pUAmi7YGw=; b=repbnrJZj50yqQmmpAePBQGJJcd1qjcG6iyLa8qGOQPQBHQYbNnjVOgNYvsXww0IOB sI0rEs+LwfYgrofLfTXxJv/WL5JuWucwHz+gCG39FYwSbSYJEWyiVy/QNTsuNhBMYQkb nlynX/v2WY2/oiFnm/cqDEowYscwq5BU0sKFstvOAYvJ21p8GV2AEYq/5ggYINKvc2BW BiYQOuxMQBFBuSNkiPspFVPGDB7KMu7ohLovRH/o78aRwAa6Wjs/eMxtCuzr7r3Gl/iP KbAr+U3y/FbdSE2jafyx3/vboIyz4B0Kj3waRV6HvSrmdgV5wBA/g9PEjwNbRbfs/ebV EuiA== X-Gm-Message-State: AHPjjUhW3yuoZMtdb2JdrBPTNrMdqifVGzZm9KRp5pDcSb5KBYV585iS c/ORX8MDVRcX3Q== X-Google-Smtp-Source: AOwi7QBVNiFT5O8sM61k9fJhR9fTNrhxv3J02gvp795rayOxtmEJa0ojfgVnu8JzB/JJXj1MnTF+pA== X-Received: by 10.202.77.139 with SMTP id a133mr5792706oib.124.1504938553025; Fri, 08 Sep 2017 23:29:13 -0700 (PDT) Received: from mail.outlook.com ([52.165.156.32]) by smtp.gmail.com with ESMTPSA id b130sm4181005oih.43.2017.09.08.23.29.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Sep 2017 23:29:12 -0700 (PDT) Date: Sat, 9 Sep 2017 06:29:11 +0000 (UTC) To: Rowan Collins , Haitao Lv Cc: internals@lists.php.net Message-ID: <9F8F6CAC61426010.7157d410-6f93-4ae2-ba73-92447bb47259@mail.outlook.com> In-Reply-To: <4D64625B-AA30-4493-84F0-F523ED459D60@lvht.net> References: <7E991FBB-C115-4AB9-B904-EBE7C0F24089@lvht.net> <8DB5D7F2-CB7A-4324-AB9F-D9934DD9C108@lvht.net> <4D64625B-AA30-4493-84F0-F523ED459D60@lvht.net> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_2331_1560821523.1504938551802" X-Mailer: Outlook for iOS and Android Subject: Re: [PHP-DEV] add Fiber (sackful coroutine) support From: hufeng1987@gmail.com (zixu mo) ------=_Part_2331_1560821523.1504938551802 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit the best corotine . must be golang go and chan. very easy to use. non blocking. On Sat, Sep 9, 2017 at 2:28 PM +0800, "Haitao Lv" wrote: > On 2 Sep 2017, at 20:19, Rowan Collins wrote: > > On 1 September 2017 14:02:29 BST, Haitao Lv wrote: >> >> Fiber is a lightweight thread. Please see >> https://en.wikipedia.org/wiki/Fiber_(computer_science) >> And ruby support Fiber. Please see >> https://ruby-doc.org/core-2.4.1/Fiber.html > > Ah, thanks, that makes more sense now. > > I note that the examples there all implement it not as a keyword, but as a library function, which maybe makes more sense: whereas "yield" turns a function declaration into a generator declaration, "Fiber\yield", as we might call it, is just a function call which can happen anywhere and manipulates some global state. As the Zend Engine does not offer API to pause execution, I cannot implement the await without introducing a new keyword (just like yield). > The choice of "await" also feels odd: you're not awaiting the thing on the right-hand side of the keyword, you're sending it somewhere and awaiting something else. await is chosen because we cannot reuse the `yield` keyword. Maybe we can choose a more proper keyword. >> You can see the await as a resumable return. The value after it >> will be returned and the function >> will be paused. > > Again, this explanation doesn't make sense if you can call foo() without any Fiber code. If there isn't an active Fiber to pause, the "await" line can't "return" anything; it will presumably throw an error of some sort. > > function foo($x) { > $y = Fiber\yield($x); > return $x + $y; > } > echo foo(1); > > The 1 isn't "returned" to the echo, it's passed off to a global function for further processing. This makes much more sense to me than implying that foo() is no longer a normal function. await is not yield. It need a separate vm stack to work. So call the foo function without a Fiber will throw a runtime error exception. > >>> Your ->resume() doesn't seem to do anything a normal generator can't, >> except that the yield is nested deeper. >> >> The await is a nested deeper yield! > > Yes, I understand that, but that seems to be completely unrelated to the API design of having resume() act as start, continue, and final result all rolled into one. As I say, I didn't entirely follow the reasoning for allowing return in generators, but if Fibers are used for the same purpose, I would expect the same concerns to arise. > > However, I think the comparison to generators may be more distracting than useful, as they seem to be very different solutions to the same or related problems. If fiber were implemented, the generator would be a special fiber. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php ------=_Part_2331_1560821523.1504938551802--