xl45 / shedskin

Automatically exported from code.google.com/p/shedskin
0 stars 0 forks source link

time.sleep() 100% cpu in Windows #28

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create a script that uses time.sleep()
2. shedskin.bat <script>; make
3. Monitor CPU utilization of the script

What version of the product are you using? On what operating system?
0.1 on Windows XP

Original issue reported on code.google.com by endeavor...@gmail.com on 19 Feb 2009 at 4:14

GoogleCodeExporter commented 8 years ago
hiya,

thanks for reporting! this is a known problem, where a busy loop is used, in
lib/time.cpp:

void *sleep(double s) {
    timeval tim;
    double t1, t2;

    gettimeofday(&tim, 0);
    t1=tim.tv_sec+(tim.tv_usec/1000000.0);
    do {
        gettimeofday(&tim, 0);
        t2=tim.tv_sec+(tim.tv_usec/1000000.0);
    } while (t2-t1 < s);

    return NULL;
}

I am open to suggestions on how to improve this (preferrable so that it works 
on all
supported platforms).

Original comment by mark.duf...@gmail.com on 19 Feb 2009 at 10:47

GoogleCodeExporter commented 8 years ago
Yes, I saw this, and I've been looking into solutions. Unfortunately, my c++ is 
iffy.
Windows and linux have separate functions for sleep, there is nothing in the 
standard
library. Including windows.h in time.cpp breaks it. I haven't had time to look 
into
it, but I'm considering an ugly hack where I just create a seperate c++, include
windows.h there, then call Sleep from within that file... Either that or fixing
time.cpp with #include <windows.h>

Hopefully I'll have some more time to look into it. This is definitely an 
awesome
project.

Original comment by endeavor...@gmail.com on 20 Feb 2009 at 3:57

GoogleCodeExporter commented 8 years ago
Thanks for looking into this. I'd be happy to accept a Windows-only solution, 
as long
as we can keep things within time.cpp..

My guess is that the MingW version now used is a bit broken, because I initially
stripped it of all unnecessary stuff.. Maybe it is just missing some header 
files? 

Original comment by mark.duf...@gmail.com on 23 Feb 2009 at 11:49

GoogleCodeExporter commented 8 years ago
I don't know if this could/would help:

http://www.cplusplus.com/reference/clibrary/ctime/CLOCKS_PER_SEC/
http://www.cplusplus.com/reference/clibrary/ctime/clock/

Regards

Original comment by thari...@gmail.com on 16 Jun 2009 at 8:22

GoogleCodeExporter commented 8 years ago
thanks.. this doesn't solve the busy-loop problem though. I think we need to use
<windows.h>, and figure out (if necessary) why that doesn't work with the 
current
version of MingW packaged with Shedskin.

Original comment by mark.duf...@gmail.com on 17 Jun 2009 at 10:31

GoogleCodeExporter commented 8 years ago
oh, I see the UNIX version is now also busy-loop.. not sure if that was ever 
different.

Original comment by mark.duf...@gmail.com on 17 Jun 2009 at 10:33

GoogleCodeExporter commented 8 years ago
What I'm going to suggest is kind of a crappy solution... You know that Unix 
system's
shells (at least the ones I used) all have the sleep utility. So, a (fix the 
hole
with masking tape like solution) would be a system call...

Anyway, I'll try to find a solution for that problem...

BTW, I really enjoyed your initiative. I had the same idea (though I don't 
understand
that much of C++)! Congratz!

Original comment by thari...@gmail.com on 17 Jun 2009 at 11:49

GoogleCodeExporter commented 8 years ago
thomas spura fixed the problem under Linux, at least:

http://code.google.com/p/shedskin/source/detail?r=896

Original comment by mark.duf...@gmail.com on 21 Aug 2009 at 3:52

GoogleCodeExporter commented 8 years ago

Original comment by mark.duf...@gmail.com on 21 Mar 2010 at 9:52

GoogleCodeExporter commented 8 years ago
windows support will be dropped with 0.4, so I'm closing all windows-only 
issues. 

Original comment by mark.duf...@gmail.com on 22 Mar 2010 at 9:56