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

threadDelay impl does not prevent underflow #129

Closed
nfrisby opened this issue Dec 13, 2023 · 3 comments · Fixed by #138
Closed

threadDelay impl does not prevent underflow #129

nfrisby opened this issue Dec 13, 2023 · 3 comments · Fixed by #138
Labels
bug Something isn't working si-timers Issues / PRs related to si-timers

Comments

@nfrisby
Copy link
Contributor

nfrisby commented Dec 13, 2023

Describe the bug
If the argument to threadDelay is "very negative", it will underflow.

To Reproduce
Steps to reproduce the behaviour: I didn't record them. I think pass a negative duration to threadDelay that is between -2X and -1X where X is the minBound of Int.

Expected behaviour
Every non-positive argument should have the same behavior.

@coot
Copy link
Collaborator

coot commented Jan 14, 2024

I don't see anything wrong here (using threadDelay from si-timers):

λ putStrLn $ IOSim.ppTrace $ runSimTrace (threadDelay ((-1) * fromIntegral  @Int maxBound))
0s - Thread []   main - ThreadDelay TimeoutId 0 Time -9223372036854775807s
0s - Thread []   main - ThreadDelayFired TimeoutId 0
0s - Thread []   main - ThreadFinished
0s - Thread []   main - MainReturn () []
λ putStrLn $ IOSim.ppTrace $ runSimTrace (threadDelay ((-1.5) * fromIntegral  @Int maxBound))
0s - Thread []   main - ThreadDelay TimeoutId 0 Time -13835058055282163710.5s
0s - Thread []   main - ThreadDelayFired TimeoutId 0
0s - Thread []   main - ThreadFinished
0s - Thread []   main - MainReturn () []
λ putStrLn $ IOSim.ppTrace $ runSimTrace (threadDelay ((-2) * fromIntegral  @Int maxBound))
0s - Thread []   main - ThreadDelay TimeoutId 0 Time -18446744073709551614s
0s - Thread []   main - ThreadDelayFired TimeoutId 0
0s - Thread []   main - ThreadFinished
0s - Thread []   main - MainReturn () []

@nfrisby
Copy link
Contributor Author

nfrisby commented Feb 1, 2024

Does microsecondsAsIntToDiffTime minBound - picosecondsToDiffTime 1 trigger it?

@coot
Copy link
Collaborator

coot commented Feb 1, 2024

Testing it with IOSim was not a good idea, because in IOSim we don't do DiffTime conversions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working si-timers Issues / PRs related to si-timers
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants