Thread implementation - difference?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
extremecoder
Member
Member
Posts: 59
Joined: Tue May 23, 2006 11:00 pm

Thread implementation - difference?

Post by extremecoder »

What is the difference between implementing the thread in the user space and in the kernel space ?
User avatar
Daedalus
Member
Member
Posts: 74
Joined: Sun Oct 16, 2005 11:00 pm
Location: Australia
Contact:

Re: Thread implementation - difference?

Post 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.
Myth OS is awaiting a revival ...
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Re: Thread implementation - difference?

Post 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
Last edited by JAAman on Thu May 25, 2006 11:00 pm, edited 1 time in total.
rexlunae
Member
Member
Posts: 134
Joined: Sun Oct 24, 2004 11:00 pm
Location: North Dakota, where the buffalo roam

Re: Thread implementation - difference?

Post 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...
Last edited by rexlunae on Thu May 25, 2006 11:00 pm, edited 1 time in total.
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Re: Thread implementation - difference?

Post 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
extremecoder
Member
Member
Posts: 59
Joined: Tue May 23, 2006 11:00 pm

Re: Thread implementation - difference?

Post 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 ?
Post Reply