test threads

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
GLneo

test threads

Post by GLneo »

hi all, ok, im trying to start multitasking with something like the F1 keys to switch, but i have no "easy" way to load test threads from disk(i do have fdc driver but don't like using it) and i saw people doing it like:

Code: Select all

void task0()
{
    while(1)
    {
        printf("something");
    }
}
void task1()
{
    while(1)
    {
        printf("something else");
    }
}
and use there swicther to swith them, what are they doing???, thx
JoeKayzA

Re:test threads

Post by JoeKayzA »

Hi!

The term 'thread' normally corresponds to a flow of control _within_ one program, or the kernel. When you want to 'load a thread from disk', I suspect you confuse this with 'loading a program' from disk, and creating a process for it...

When you spawn a thread, you normally define an 'entrypoint' where the thread starts execution, this can be a C function, of course. So when you have two C functions, and spawn a thread for each of them, these two functions seem to be executed 'in parallel'. That's the sense of multithreading. Basically, you intercept a timer interrupt, then save the processor's state (the register contents) to some 'thread' structure, then load the state of the next thread to run, and return from the interrupt. The CPU will continue running in the next thread then, the threads theirselves shouldn't even notice that they have been interrupted.

If you need information on how to do task switching and multithreading, check the Bonafide tutorials http://www.osdever.net (they helped me a lot), or the OS FAQ. Besides that, we recently had a thread on this board on how to do task switching. If you have further questions, feel free to post here, of course :).

cheers Joe
GLneo

Re:test threads

Post by GLneo »

that makes sence, thx ;)
Post Reply