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.
Well, if timer rolls over to zero during the wait function, then u have a infinite loop. How do you avoid this? especially in userland when there are applications that do things like get_timerticks() and then do a loop waiting for timer to become greater...
is there a kernel way to do this? or is it just something application programmers should be aware of?
I just feel I should point out to anyone using the above snippet that if the process gets no run time during the period where p == end (very likely), this process will go in to an infinite loop.
pcmattman wrote:Or even keep track of when an overflow does occur, and increment a variable numOverflows or something.
If timer is a 32 bit value and numOverflows is a 32 bit value, you could just take michael1234's suggestion and use a 64 bit variable to start with (on architectures that support it).
I just feel I should point out to anyone using the above snippet that if the process gets no run time during the period where p == end (very likely), this process will go in to an infinite loop.
A valid point, and a definite fault in the snippet I posted above.
Realistically you would want to have the process put onto a sleep queue and every timer interrupt check the sleep queue to find if a process needs to be woken. At least, that's one (/yet another) way of doing it .