• 0

User Level Threading


Question

Hi

I am doing a (personal) research about User Level Threading and User Level Context Switching/Scheduling. I have google alot and found some very useful information about user level threading, its concepts and design. But I was not able to find anything about how the actual Context Switch occurs - context switching at the user level not at the kernel level.

I am currently developing on a Linux machine because it offers more control at a lower level then Windows. Does any have some info (or maybe a book) about this topic. Any help would be greatly appreciated.

Cheers

George

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

By context switching, are you refering to the act of switching protection "rings" (from user to kernel & vice versa). If this is the case, it's really processor dependent becasue each processor handles protection a bit differently differently.

Link to comment
Share on other sites

  • 0

nope, by context switch i mean ... the kernel thread is executing a user thread, but after some time it will switch to another user thread. To the OS/kernel, it still appears that one kernel thread is running, but infact there are a number of user level threads running simultaneously.

The idea to do this is to save the CPU context (state of registers) and restart the next thread in queue but I can't find any info on how to actually implement it.

I don't know if i was clear enough about this, if you have any questions just ask.

Cheers

George

Link to comment
Share on other sites

  • 0

Oh, I'm not sure that "context switching" is the correct term to use here but I'll just go with the flow. When you say that a number of threads are running "simultaneously", you may or may not be right. If you have an SMP machine, then there are more than one threads running at the same time. If you have a single processor machine, then only one thread can run at any given moment (not including hyperthreading which is a mash of the two).

For a single processor machine, the CPU starts up a user-level task (I'll use the word task or process instead of thread). When it comes time for another task to run for it's fair share of time, the CPU will interrupt the current task, then you save the task's registers, load the new tasks registers and return to the task. Now the current task will be the new one that was just switched into. So where do the registers get saved? Usually you have a memory structure which contains a description of each task. Within this structure is a some space to save your registers.

Without getting into any more detail, are you programming for the x86 architecture. If not, I can provide a little more theory but nothing practical. If you are, then I'm sure I can help you.

P.S. I said above that the term "context switching" is not correct here. This is because a context switch refers to the act of changing protection levels, from user to kernel and vice versa, not switching between tasks. Context switching is still an important part of task switching and scheduling.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.