Global Timer Issue

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
Nessphoro
Member
Member
Posts: 308
Joined: Sat Apr 30, 2011 12:50 am

Global Timer Issue

Post 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.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Global Timer Issue

Post by bluemoon »

Is Ticks thread safe?
How do you invoke the scheduler (before or after print Ticks?) and how it work?
User avatar
Nessphoro
Member
Member
Posts: 308
Joined: Sat Apr 30, 2011 12:50 am

Re: Global Timer Issue

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