0

According to the video, which is from the Introductory Operating Systems course in Udacity:

For a user-level thread to actually execute first, it must be associated with a kernel-level thread. And then, the OS level scheduler must schedule that kernel-level thread onto a CPU.

According to Remzi H. Arpaci-Dusseau's book (Operating Systems: Three Easy Pieces) in chapter 6:

We have described some key low-level mechanisms to implement CPU virtualization, a set of techniques which we collectively refer to as limited direct execution. The basic idea is straightforward: just run the program you want to run on the CPU, but first make sure to set up the hardware so as to limit what the process can do without OS assistance.

This general approach is taken in real life as well. For example, those of you who have children, or, at least, have heard of children, may be familiar with the concept of baby proofing a room: locking cabinets containing dangerous stuff and covering electrical sockets. When the room is thus readied, you can let your baby roam freely, secure in the knowledge that the most dangerous aspects of the room have been restricted.

In an analogous manner, the OS “baby proofs” the CPU, by first (during boot time) setting up the trap handlers and starting an interrupt timer, and then by only running processes in a restricted mode. By doing so, the OS can feel quite assured that processes can run efficiently, only requiring OS intervention to perform privileged operations or when they have monopolized the CPU for too long and thus need to be switched out.

First quote states a kernel-level thread has to associated with a user-level thread to run, but according to the second quote, OS directly executes the user-level thread but under strict control, without any associations.

Questions:

1) I'm a newbie Linux user. Which of the above approach is more correct for Linux operating system?

2) Yes there are quite many posts and links about Multithreading models in the internet. But can't find a single example code. Can you give a simple example C code on One-to-One and Many-to-One for Linux?

  • See my answer: https://stackoverflow.com/questions/39185134/how-are-user-level-threads-scheduled-created-and-how-are-kernel-level-threads-c/39185831#39185831 – Craig Estey Jul 01 '17 at 22:47
  • Great intro article [light-weight-processes-dissecting-linux-threads](http://opensourceforu.com/2011/08/light-weight-processes-dissecting-linux-threads/) – YLJ Jul 02 '17 at 15:03

0 Answers0