Announcement

Collapse
No announcement yet.

Hack Adds Async Cooperative Multitasking For Fake Multi-Threading

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hack Adds Async Cooperative Multitasking For Fake Multi-Threading

    Phoronix: Hack Adds Async Cooperative Multitasking For Fake Multi-Threading

    The latest addition to Facebook's PHP-based Hack programming language is an interesting concept of cooperative multitasking for providing threading-like capabilities while only really executing one piece of code at a time...

    Phoronix, Linux Hardware Reviews, Linux hardware benchmarks, Linux server benchmarks, Linux benchmarking, Desktop Linux, Linux performance, Open Source graphics, Linux How To, Ubuntu benchmarks, Ubuntu hardware, Phoronix Test Suite

  • #2
    You can already do async request with curl and mysqli in php

    Comment


    • #3
      Sounds like a coroutine. These have been used for decades.

      Comment


      • #4
        I'd rather use Promises and an API designed to use them.

        Comment


        • #5
          In still waiting for something like symfony C++. Maybe with C++ reflection proposal? Who knows!

          Comment


          • #6
            BFD. Welcome to Mac OS 9.

            Comment


            • #7
              Originally posted by Marc Driftmeyer View Post
              BFD. Welcome to Mac OS 9.
              It's true that this is hardly a new concept (and that it was provided by the Thread Manager in pre-OSX MacOS).
              That doesn't mean it's a useless concept.
              I made aggressive use of this when I wrote an MPEG decoder for MacOS. Decoding an MPEG stream means decoding an interleaved stream of data. You parse material at the "System" level till you hit say a video marker, then you parse video material till you hit the end of that, return to the System level, parse a little more, and maybe hit an audio marker.

              The point is, when you switch from System parsing to Video or Audio parsing, you're switching contexts --- you're now dealing with a whole new set of different data structures. You CAN write code like this in a traditional form, or as a godawful state machine, but by far the most natural way to proceed is as coroutines/non-pre-emptive threads. You have a system thread, a vide thread, an audio thread, each maintaining their own state in their set stack and registers. At the point where you need to switch parsing from System to Video, you simply swap in the Video thread, and when you hit a marker indicating a return to System parsing, you again swap back to the System thread. EXTREMELY simple to reason about and set up, and a perfect match to the problem.
              I suspect a model like this makes sense in many contexts where you're parsing muxed data of some form.

              [Note, this has nothing to do with asynchronous issues of presenting the frames and the audio at the correct time. That's a different problem which occurs AFTER data stream parsing, and is solved by different techniques --- interrupts in the old MacOS days, though these days thankfully we have rather better abstractions.]

              Comment

              Working...
              X