Multi threading

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
itisiuk
Member
Member
Posts: 98
Joined: Mon Mar 24, 2008 1:46 pm

Multi threading

Post 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.
User avatar
lukem95
Member
Member
Posts: 536
Joined: Fri Aug 03, 2007 6:03 am
Location: Cambridge, UK

Post 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.
~ Lukem95 [ Cake ]
Release: 0.08b
Image
itisiuk
Member
Member
Posts: 98
Joined: Mon Mar 24, 2008 1:46 pm

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