Page 1 of 1

Thread implementation - difference?

Posted: Wed May 24, 2006 11:00 pm
by extremecoder
What is the difference between implementing the thread in the user space and in the kernel space ?

Re: Thread implementation - difference?

Posted: Wed May 24, 2006 11:00 pm
by Daedalus
When the thread is in user space, there are a few commands that are restricted from being used. Also, usually various memory ranges can be set by your boot code to be read only by user space processes.
I can't actually recall what these are, maybe someone else can.

In kernel mode, it has full access to the entire system and all commands.

If I'm wrong here, feel free to correct me.

Re: Thread implementation - difference?

Posted: Thu May 25, 2006 11:00 pm
by JAAman
the normal way is to use paging to isolate certain parts of memory (areas used by the kernel) so that applications cannot read or write to them (its also possible to do this with segmentation, but its much more complicated and less flexable)

for more details, check out the Intel manuals vol 3 chapters 3 & 4(revision 16 -- single volume 3)

i highly recomend reading at least these chapters (or, better, the whole volume 3) before proceeding -- its very important that you understand everything in these chapters

if you dont understand anything in those chapters, please feel free to post further (more specific) questions


btw: the manuals can be downloaded, or hardcopies orderd, from the link in my signature -- but in the new ones, volume 3 has been split into 2 books, so im not sure about the new sections -- i would guess that those chapters are still chapters 3 & 4 in vol 3a, but i dont have them yet so i cannot be certain, but the chapter titles should be:

protected-mode memory management

and

protection


hope this helps you

Re: Thread implementation - difference?

Posted: Thu May 25, 2006 11:00 pm
by rexlunae
Daedalus wrote:When the thread is in user space, there are a few commands that are restricted from being used. Also, usually various memory ranges can be set by your boot code to be read only by user space processes.
I can't actually recall what these are, maybe someone else can.

In kernel mode, it has full access to the entire system and all commands.

If I'm wrong here, feel free to correct me.
All the library functions that are used by a multithreaded application (regardless of the threading being in kernel or user space) must be thread safe. Unfortunately, many of the standard interfaces in C are difficult to make safe. Basically, if a function relies on global or static variables, it must have appropriate locking added, or better yet, it must be reimplemented to use only parameters and local variables if possible. Another option would be to have a bit of memory that is allocated on a per-thread basis. Some mechanisms are very difficult to effectively lock, for instance, the errno global variable.

The main difference that I am aware of between kernel and user mode threading is that the kernel is able to schedule the threads more intelligently than the userland task is. As an example, consider a program that contains an IO thread. The IO thread reads, and because the data has to be retrieved from disk, the call blocks. However, if the kernel is not aware of the threading, it will probably block the entire process, meaning that none of the threads can run until the read call is completed. This can have a sever impact on performance, and in some cases can make multithreading actually less efficient. However, if the kernel schedules the threads, it can block just that thread and allow the others to keep running.

JAAman: I don't quite see what your post has to do with threading...

Re: Thread implementation - difference?

Posted: Thu May 25, 2006 11:00 pm
by JAAman

JAAman: I don't quite see what your post has to do with threading...
sorry -- i was reading several threads at once, and must have gotten them mixed up -- i dont know where that came from

Re: Thread implementation - difference?

Posted: Sun May 28, 2006 11:00 pm
by extremecoder
Hello rexlunae, you are exactly right. That's what I am looking for. It seems, even kernel level threads are costlier, since it has to make traps to switch from one thread to another. Somewhere I have read about the hybrid model too.

By the by, what's the IRC channel and server for this community ?