[Python-ideas] PEP 525: Asynchronous Generators

Chris Angelico rosuav at gmail.com
Wed Aug 10 23:46:22 EDT 2016


On Thu, Aug 11, 2016 at 1:17 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
>> Lately, I talked to friend of mine about async and his initial reaction
>> was like "hmm that reminds me of early programming days, where you have to
>> explicitly tell the scheduler to get control back". He's much older than me,
>> so I think it was interesting for him to see that history is repeating
>> again.
>
>
> Yep, cooperative multi-threading predated pre-emptive multi-threading by
> *many* years (one of the big upgrades between Mac OS 9 and OS X was finally
> getting a pre-emptive scheduler). The difference is that where an OS is
> scheduling CPU access between mutually unaware applications, application
> developers can assume that other control flows *within* the application
> space are *not* actively hostile.
>

Mac OS lagged behind other operating systems in that. Back before
1990, OS/2 offered the PC world an alternative to the cooperative
multitasking of Windows. The basic difference was: In Windows (that
being the 3.x line at the time), an infinite loop in your program will
bring the whole system down, but in OS/2, it'll only bring your
program down. Windows NT then built on the OS/2 model, and Win2K, XP,
and all subsequent versions of Windows have used that same preemption.
Linux takes things slightly differently in the way it handles threads
within a process, but still, processes are preemptively switched
between.

Though tongue-in-cheek, this talk shows (along the way) some of the
costs of preemption, and thus some of the possibilities you'd open up
if you could go back to cooperation. While I don't think the time is
right for *operating systems* to go that route, it's definitely an
option for tasks within one process, where (as Nick says) you can
assume that it's not actively hostile. On the other hand, I've had
times when I have *really* appreciated preemptive thread switching, as
it's allowed me to fix problems in one of my threads by accessing
another thread interactively, so maybe the best model is a collection
of threads with a master.

https://www.destroyallsoftware.com/talks/the-birth-and-death-of-javascript

ChrisA


More information about the Python-ideas mailing list