Mac OS equivalent of Windows Fibers API?

I ask about this out of curiosity.

Windows provides what they call the Fibers API , which is an API for lightweight user processes / threads.

I was wondering if Mac OS supports such features. To my knowledge, the closest Unix equivalent for this would be a setcontext family of functions. However, attempting to invoke such an API on a Mac raises warnings that features are deprecated with OSX 10.6. Also, when I try to compile and run the example specified in the Wikipedia link above, I get a seg error on my machine on the first swapcontext .

Thus, it is obvious that the setcontext API is not suitable for Mac. At least not anymore. Is there any other way to achieve an easy flow of users on Mac OS? Does the system provide such functionality?

+6
source share
1 answer

No, there is no equivalent for OS X (or most UNIX-based systems, for that matter). A number of ucontext functions ucontext deprecated from the POSIX standard and did not provide for replacement.

Closest you can switch to OS X Grand Central Dispatch , which allows you to create dispatch queues that execute “blocks” (essentially a function). Processing of these queues can be paused and resumed, like fibers, although you cannot stop and resume execution in the middle of a block.

There's also Boost.Context , which provides similar ucontext functionality (and possibly even uses it internally), although it is a C ++ library.

+2
source

Source: https://habr.com/ru/post/987391/


All Articles