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

Use of usleep in conflict with SUSv2 (fencepost error) #714

Open
he32 opened this issue Feb 9, 2012 · 5 comments
Open

Use of usleep in conflict with SUSv2 (fencepost error) #714

he32 opened this issue Feb 9, 2012 · 5 comments

Comments

@he32
Copy link

he32 commented Feb 9, 2012

SUSv2 says in http://pubs.opengroup.org/onlinepubs/7908799/xsh/usleep.html:

The useconds argument must be less than 1,000,000.
The NetBSD libc implementation enforces this limitation.

However, parrot will try to use that exact value, due to a fencepost error,
and this causes several of the timer tests to fail.

Fix for parrot 3.9.0:

--- src/scheduler.c.orig 2011-10-18 22:44:11.000000000 +0000
+++ src/scheduler.c
@@ -993,7 +993,7 @@ Parrot_cx_schedule_sleep(PARROT_INTERP,
Parrot_cx_runloop_wake(interp, interp->scheduler);

 /* A more primitive, platform-specific, non-threaded form of sleep. */
  • if (time > 1) {
  • if (time >= 1) {
    /* prevent integer overflow when converting to microseconds
    * and problems in platforms that doesn't allow usleep more
    * than 1 second */
@he32
Copy link
Author

he32 commented Feb 9, 2012

Bah, the diff didn't format all that well, let's try to do it better:

--- src/scheduler.c.orig        2011-10-18 22:44:11.000000000 +0000
+++ src/scheduler.c
@@ -993,7 +993,7 @@ Parrot_cx_schedule_sleep(PARROT_INTERP, 
     Parrot_cx_runloop_wake(interp, interp->scheduler);

     /* A more primitive, platform-specific, non-threaded form of sleep. */
-    if (time > 1) {
+    if (time >= 1) {
         /* prevent integer overflow when converting to microseconds
          * and problems in platforms that doesn't allow usleep more
          * than 1 second */

@leto
Copy link
Member

leto commented Feb 9, 2012

This patch no longer applies to 4.0.0 but I made it work and currently testing this. Nicely done! 🤘

Just to be clear, where you seeing timer test failures or were you seeing the Timer PMC tests intermittently hang forever?

@leto
Copy link
Member

leto commented Feb 9, 2012

Sadly, I am still seeing t/pmc/timer.t hang forever after test 11. That being said, it could be that my hanging issue is totally different than this fencepost error. Not quite sure yet.

@leto
Copy link
Member

leto commented Feb 9, 2012

I made a branch for this patch: https://github.com/parrot/parrot/tree/714/scheduler_bug

Can we get some testing on various platforms?

@he32
Copy link
Author

he32 commented Feb 10, 2012

This patch no longer applies to 4.0.0 but I made it work and
currently testing this. Nicely done! 🤘

Yah, I saw that construct had gone in 3.10.0. I'm seeing New and
Exciting test failures on that version, though...

Just to be clear, where you seeing timer test failures or
were you seeing the Timer PMC tests intermittently hang
forever?

I was seeing test failures, as in:

Test Summary Report

t/op/time.t (Wstat: 0 Tests: 19 Failed: 2)
Failed tests: 5-6
t/pmc/timer.t (Wstat: 512 Tests: 9 Failed: 2)
Failed tests: 4, 6
Non-zero exit status: 2
t/pir/timer_exit.t (Wstat: 0 Tests: 1 Failed: 1)
Failed test: 3
Parse errors: Tests out of sequence. Found (3) but expected (1)

E.g. one of the tests did "sleep 1", which instead of doing sleep(1)
ended up doing usleep(1000000), which promptly returned -1 and set
errno to EINVAL, and time didn't progress notably, so the test failed.

Regards,

  • Håvard

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