TAGS :Viewed: 3 - Published at: a few seconds ago

[ Creating a user level thread ]

I have an assignment that consists of creating a user level thread package. I read through this thread, and it answered a lot of my questions. However, I am still confused about a few things...

Primarily, I cant understand how to actually create a user-level thread without the pthread library... I have a thread structure that takes into account the stack, the stack pointer, thread id, and the thread state. I'm guessing this is a simple task, but I cant wrap my mind around how a thread gets "created" in the current process.

Another question I have deals with how the thread gets passed to the scheduler. I have a round robin scheduler implemented, and a signal handler that handles an interrupt every 100ms to check for thread states. But how is the scheduler aware of the threads?

I feel like I am missing a concept of user-level threading that is preventing me from understanding thread creation and manipulation.

Please help me out! Thanks in advance!

Answer 1

User-level threads can be created in different ways. One of them is through context switching. There will be a single process and we change the context in a round-robin fashion.

We change the context to some different thread after every short time interval. Although it is a single process, the fast switching makes it looks as if they are running parallel.

To make the scheduling possible, we need to keep track of all the threads currently running. When an interrupt occurs, the corresponding routine that will execute, contains the code to swap the current context with the next thread. In this way the scheduling is handled.

More on this on my blog :)