Search code examples
c++windowsoperating-systemfiber

Auto-Switch-Context between a list of fibers


Is there a way to implement system like OS that allocates time for each process\thread with fibers? I mean like when I run a process and do an infinite loop inside it, the OS can still function normal on one core. (It switch context automatically without the process's permission or order)

I don't have internal functions that the fibers use that I can check the time and switch-context.


Solution

  • Well, sure there is, the OS does it. Although doing it yourself in your own process without using the OS services is a bit hard.

    There was an old book, called Born to Code in C by Herbert Schildt, that had a rudimentary multi-threading mechanism implemented in C and running in the same process.