1

I am trying to grasp the idea of thread scheduling in operating system. My professor said - I can use cooperative scheduling at process level, and kernel has inbuilt preemptive scheduling.

Now I am confused, say my process has 2 threads, and kernel has timer based thread scheduling. Now in my process thread after some particular code, I have invoked the yield() function to transfer the control to other thread in my process. But, before reaching this yield function in my program, what happens if the kernel automatically holds my thread (owing to preemptive nature of scheduling) and transfer control to some other thread. Then the whole idea of having control on the threads of my process goes void.

If someone can kindly answer I would greatly appreciate!

user3001408
  • 310
  • 5
  • 20
  • 1
    A search for "M:N thread model" might provide some interesting reading. User space threads can theoretically avoid some context switch overhead (a function call is generally substantially cheaper than a system call) and can more easily use application-specific knowledge for scheduling. However, most systems seem to have moved to a 1:1 model. (This is complicated by something like the MIPS MT ASE which has a user-level `fork` instruction that spawns an additional hardware thread, with `yield` applying hardware scheduling, including termination.) –  Jun 09 '14 at 00:54
  • 1
    Related question: [Hybrid Thread Model (M:N) Implementation](http://stackoverflow.com/q/4249124/2467198). –  Jun 09 '14 at 00:55

0 Answers0