Page 1 of 1

Global Timer Issue

Posted: Sun Jun 24, 2012 3:06 am
by Nessphoro
Hello, mates,

I've got my multitasking working and it is working - well nice enough.
Now I encountered a "how is this even possible" kind of issue.
So basically, I have three threads that just "hlt" in a loop - their page directories are all linked above 3Gb mark and each has its own stack.
My IRQ0 event handler looks like this:

Code: Select all

           Ticks++;
            if(Ticks%1000==0)
            {
                *Graphics::GetConsole()<<Ticks<<endl;
            }
            ...
The problem is, every 1000 ticks( 1 second) I get three lines in the console of identical value. Four if I have four threads running, and so forth.

Any ideas on how it's possible? I have verified that Ticks points to the same physical address in all threads, and also interrupts are disabled in the IRQ stub.

Re: Global Timer Issue

Posted: Sun Jun 24, 2012 3:34 am
by bluemoon
Is Ticks thread safe?
How do you invoke the scheduler (before or after print Ticks?) and how it work?

Re: Global Timer Issue

Posted: Sun Jun 24, 2012 1:14 pm
by Nessphoro
Aye, ticks are volatile.
Scheduler is invoked after the print, and it will delay the switch until the end (iret) where a small routine will switch address space and esp and restore the registers