1
$\begingroup$

This is with respect to user-level threads where the kernel only knows about the process as a whole, and threads are created and maintained in the user space. Each thread has its PC, registers, stack and thread control block. To my knowledge, updating PC (or any system register) or access of the code segment can only be done in the kernel mode (since it has to be protected from outside access). If this is true, how can user-level threads maintain (or update) their state information (PC, other registers, thread control block, etc.) at the user level instead of the kernel level?

To put it in short, could anyone please explain what actually happens under the hood, and how thread-level context switches are realised at the user level?

$\endgroup$
  • $\begingroup$ "Updating PC or access of the code segment can only be done in the kernel mode" - what do you mean by this? $\endgroup$ – Gokul Nov 30 '18 at 19:09
  • $\begingroup$ I mean to say that the program counter or the text segment (code segment) is not accessible at the user level. The OS protects these from access outside the OS boundary (correct me if I am wrong). $\endgroup$ – Duncan Nov 30 '18 at 19:22
  • $\begingroup$ I don't think that's correct. Most programs run at the user level as a process and every process has its own memory image consisting of stack, code, data and a heap. The protection is usually between processes - a process cannot access the contents of another process without adequate permissions and if it tries to, the OS intervenes and throws an error. EDIT: Memory protection is usually given by the MMU, not the OS. I was not fully correct. See here $\endgroup$ – Gokul Nov 30 '18 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.