Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What happens when millis() overflows? #45

Open
julioj4pa opened this issue Feb 1, 2020 · 3 comments
Open

What happens when millis() overflows? #45

julioj4pa opened this issue Feb 1, 2020 · 3 comments

Comments

@julioj4pa
Copy link

I'm developing opens source project to sustentable agriculture.
I want to know what happens when millis() overflows...

If I need to remove all threads -> reset millis() -> addition all threads back to ThreadController in main code.

Thank you and congratulation for awesome library.

@gregkrsak
Copy link

@julioj4pa
Copy link
Author

@gregkrsak thank you for reply.

My doubt is I need to controll it in my main code?
I'm a newbie, sorry.

Library code....
bool Thread::shouldRun(unsigned long time){
// If the "sign" bit is set the signed difference would be negative
bool time_remaining = (time - _cached_next_run) & 0x80000000;

// Exceeded the time limit, AND is enabled? Then should run...
return !time_remaining && enabled;

}

@julioj4pa
Copy link
Author

I think it doesn't have any problem because.
_cached_next_run is unsigned long too.

So when
void Thread::runned(unsigned long time){
// Saves last_run
last_run = time;

// Cache next run
**_cached_next_run = last_run + interval;**

}

_cached_next_run restarts too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants