Page 1 of 1

Multi threading

Posted: Fri Apr 04, 2008 12:26 pm
by itisiuk
so far my kernel is multi-tasking.
I am busy trying to implement multi threading into my kernel and i am having trouble understanding how to switch between tasks and then threads the task owns.
ive really hit a massive wall on this.

ive read through a few examples and this is what i think it is so far.

instead of switching between tasks using the timer you switch between threads.?
the user themselfs cause the task switching?

can anyone please explain this just in basic english for me please.

Posted: Fri Apr 04, 2008 12:58 pm
by lukem95
On a single processor system, yes that would work.

However if you have multiproccessing, it would make sense to assign each processor a thread of the current process, or in the event of a one thread process, assign each processor a one thread process.

Posted: Fri Apr 04, 2008 1:14 pm
by itisiuk
cheers.
ive been workin on this bit of code, its not all there as i just wanted to show the bit i was working on.

this should switch the to task the thread belongs to when the thread is switch

typedef struct
{
thread_t *thread;
int timeslice;
struct dispatch_t *previous;
struct dispatch_t *next;
} dispatch_t;

typedef struct
{

int id;
struct process_t *parent;
tss_t *tss;
struct thread_t *previous;
struct thread_t *next;
} thread_t;

typedef struct
{
int id;
bool state;
char name[PROCESS_NAME_LENGTH];
spinlock_t lock;
thread_t *thread_list;
struct process_t *previous;
struct process_t *next;
} process_t;

thread_t *dispatch_current_thread = NULL;
process_t *dispatch_current_process = NULL;
static dispatch_t *dispatch_current = NULL;

in schedualer handler

/* Go go the next task. */
dispatch_current = (dispatch_t *) dispatch_current->next;

dispatch_current_thread = dispatch_current->thread;
dispatch_current_process = (process_t *) dispatch_current->thread->parent;

is this correct??