Page 1 of 1

Multithreading

Posted: Mon Jun 23, 2008 10:05 am
by Jeko
I've yet implemented multitasking in my OS. Now I'm going to implement also multithreading.

I have a list of threads for each task

Code: Select all

struct task_t {
	struct thread_t *cur_thread;
	struct thread_t *first_thread, *last_thread;
	struct task_t *prev, *next;
        ...
};

struct thread_t {
        struct task_t *task;
	struct thread_t *prev, *next;
        ...
};
Is this a good method?
Or maybe I should implement something like a tree for threads (where each thread can be father or son of another thread)?

Re: Multithreading

Posted: Mon Jun 23, 2008 11:15 am
by Jeko
Another very small question: If a thread trigger an exception, must I kill the thread or the entire task?

Re: Multithreading

Posted: Mon Jun 23, 2008 11:29 am
by piranha
Firstly, wouldn't the task struct be more like:

Code: Select all

struct task {
     int pid;
     <...All other tasking info...>;
     struct task *next;
     struct task *prev;
}
struct task *current, *first, *last;
-JL

Re: Multithreading

Posted: Mon Jun 23, 2008 12:15 pm
by Jeko
piranha wrote:Firstly, wouldn't the task struct be more like:

Code: Select all

struct task {
     int pid;
     <...All other tasking info...>;
     struct task *next;
     struct task *prev;
}
struct task *current, *first, *last;
-JL
Yes...But I need to know which threads are in a task.

Re: Multithreading

Posted: Mon Jun 23, 2008 4:31 pm
by dr_evil
Do it the way you want it to be.

I have one big list with all threads, regardless of which process they belong to. That way I have fast access to a thread's data just by knowing it's ID. Every thread has a process ID which points to an entry of the process list. This system works pretty well for me.

Re: Multithreading

Posted: Tue Jun 24, 2008 2:46 am
by Jeko
Ok. Thank you for your replies... I've implemented multithreading as I said.

Now I've only a small problem... When a thread trigger an interrupt, must I kill the thread or the entire task that handles the thread?

And must I make syscalls sleep,kill,ecc. for threads or only for tasks?

Re: Multithreading

Posted: Tue Jun 24, 2008 3:15 am
by Combuster
interrupts should not kill a task. Exceptions however may be fatal if unhandled. Think for yourself whether you want to kill an entire process upon an unhandled exception or not.

Do you want sleep to suspend all the other threads as well, stopping them from doing useful work when your thread has nothing left to do at the moment?

Do you want to be able to terminate individual threads remotely, or will you always kill the entire process, maybe you want different behaviour for tasks outside the program and internal to the program.

Most of them are design choices really.

Re: Multithreading

Posted: Tue Jun 24, 2008 3:24 am
by Jeko
Combuster wrote:interrupts should not kill a task. Exceptions however may be fatal if unhandled. Think for yourself whether you want to kill an entire process upon an unhandled exception or not.

Do you want sleep to suspend all the other threads as well, stopping them from doing useful work when your thread has nothing left to do at the moment?

Do you want to be able to terminate individual threads remotely, or will you always kill the entire process, maybe you want different behaviour for tasks outside the program and internal to the program.

Most of them are design choices really.
Yes you are right! I wanted only some advices...
However I think that I'll kill an entire process on an unhandled exception, and I will give a method to kill entire tasks or only threads.
Thank you.