dhaker13 / v8-juice

Automatically exported from code.google.com/p/v8-juice
Other
0 stars 0 forks source link

setTimeout() logic/timing errors #23

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
i have finally determined that the setTimeout()/setInterval() 
implementation is fairly broken in terms of being able to run at the 
specified timeout interval. The problem is that the logic is not accounting 
for the time spent in v8 executing during _other_ threads while this one is 
sleeping.

The logic needs to be rewritten to use gettimeofday() (or similar) and some 
other waiting mechanism. i haven't the faintest clue how best to proceed.

Until then, there's:

http://github.com/visionmedia/js-mock-timers/

i will see if i can use that as a basis for implementing setTimeout() and 
friends.

Original issue reported on code.google.com by sgbeal@googlemail.com on 7 Apr 2010 at 6:38

GoogleCodeExporter commented 9 years ago
The problem may not have been exactly as i described, but here's the gist of 
it...

When a timer wakes up it waits to re-gain control of v8 via its Locker object. 
Because v8 only allows 1 thread to hold/use the vm at a time, that wait can be 
arbitrarily long. When we have multiple set...

aaaarrrgggghhhhh! i am such a f-ing moron! The buggy timing was caused by me 
sleep()ing in the handlers themselves.

Original comment by sgbeal@googlemail.com on 7 Apr 2010 at 6:48