> Protothreads are extremely lightweight stackless threads designed for severely memory constrained systems, such as small embedded systems or wireless sensor network nodes. Protothreads provide linear code execution for event-driven systems implemented in C. Protothreads can be used with or without an underlying operating system to provide blocking event-handlers. Protothreads provide sequential flow of control without complex state machines or full multi-threading.
libdispatch has none of the features listed above. You're right that libdispatch is a better choice for typical PC software -- but this is designed for devices like an 8-bit microcontroller with a kilobyte of RAM.
Any numbers on task creation/switching for protothreads? GCD tasks are extremely lightweight:
> Tasks in GCD are lightweight to create and queue; Apple states that 15 instructions are required to queue up a work
Linear code execution can be done using a serial queue.
GCD is just a convenience wrapper around thread pool. Probably inspired by Windows thread pool API introduced in Vista few years before GCD, adding API functions like SubmitThreadpoolWork.
Even on PCs with tons of resources, thread pools and coroutines are not always interchangeable.
One reason is performance, accessing a cache line shared across cores is even more expensive than cache miss.
Besides performance, writing same data from multiple threads, or doing in parallel what must be running sequentially, is a common source of bugs.
It is not about serial ordering. The coroutine code looks the same as the synchronous code. While using GCD blocks, you can still end up with callback hells. However, you can, do nicer things with GCD when build on top of https://github.com/google/promises, but that is outside of the linear code execution discussion.
> Apple states that 15 instructions are required to queue up a work
Maybe the queuing part. However the "work" (block, callback, etc) is typically dynamically allocated thingy, which can be quite expensive (and is a no-go for lots of embedded systems).
> Protothreads are extremely lightweight stackless threads designed for severely memory constrained systems, such as small embedded systems or wireless sensor network nodes. Protothreads provide linear code execution for event-driven systems implemented in C. Protothreads can be used with or without an underlying operating system to provide blocking event-handlers. Protothreads provide sequential flow of control without complex state machines or full multi-threading.
libdispatch has none of the features listed above. You're right that libdispatch is a better choice for typical PC software -- but this is designed for devices like an 8-bit microcontroller with a kilobyte of RAM.