I understand task as task in C#, but this questions is not related to C#.
Let's say I have single thread and two tasks (both CPU-bound). I would like to run them concurrently, without running one of them at the expense of starving completely the other one. How this could be implemented without assuming the code will somehow cooperate?
Is it possible to set some kind of timeout (or instruction countdown) on CPU/OS level to freeze task with its entire stack, and run the other task in the same manner, then resume the first one and so on?
This question does not go to level of multitasking with threads. It is about multitasking within single, one, thread. Task is not the same as thread.