Please disable your adblock and script blockers to view this page

Fibers: The Most Elegant Windows API


Microsoft
API

the Fibers API
POSIX
Fiber Async
DemoWindows
CreateFiber
ConvertFiberToThread
DeleteFiber
the Fiber API
Linux
Wine
this API
the Windows API
CreateFile
I/O
BSD
(Linux
IOCP (Windows


process’

’d
CreateFiber
CloseHandle
past?To

No matching tags

No matching tags


the Windows API
LPVOID
demo.c

No matching tags

No matching tags

Positivity     43.00%   
   Negativity   57.00%
The New York Times
SOURCE: https://nullprogram.com/blog/2019/03/28/
Write a review: Hacker News
Summary

elegance is the exception.That’s why, when I recently revisited the Fibers API, I was programs to await on arbitrary kernel objects.Fiber Async/await DemoWindows fibers are really just stackful, symmetric coroutines. fiber returns from its start routine, the program exits. since these both create fibers.The fiber start routine returns nothing and takes a void “user pointer”. when any fiber returns from its start routine, it’s like returning from the main function, so it should probably have returned an integer.A fiber may delete itself, which is the same as exiting the thread. are no fibers. fiber using ConvertThreadToFiber(), which returns the fiber object same fiber in two different threads at the same time.The equivalent POSIX systems was context switching. strictly limited to integers.Ultimately I like the fiber API better. pretty close, though.Windows fibers are a coroutine primitive suitable for async/await in C possible, I built async/await on top of fibers in 95 lines of code.The alternatives are to use a third-party coroutine library or to API it’s a kernel object handle.So, the await function will take a kernel object, register it with the this:While fibers are symmetric, coroutines in my async/await implementation fibers. fibers[0] wait on, just the number of co-existing fibers.When a fiber is about to return from its start routine, it yields one Fibers never a fiber actually returns:The start routine given to async_start() is actually wrapped in the The fiber scheduler, and then the fiber is resumed.That WaitForMultipleObjects() is what limits the number of fibers. it.When the awaiting fiber count is zero and the scheduler has control, all

As said here by