Multithreading

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
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Multithreading

Post 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)?
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Re: Multithreading

Post by Jeko »

Another very small question: If a thread trigger an exception, must I kill the thread or the entire task?
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

Re: Multithreading

Post 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
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Re: Multithreading

Post 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.
dr_evil
Member
Member
Posts: 34
Joined: Mon Dec 20, 2004 12:00 am

Re: Multithreading

Post 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.
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Re: Multithreading

Post 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?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Multithreading

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Re: Multithreading

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