Hi, all! i've implemented a setTimeout() function:
http://code.google.com/p/v8-juice/source/browse/trunk/src/lib/juice/time.cc (grep for "thread_setTimeout") Someone on this list once pointed out to me that it doesn't work just like a browser's variant because it literally runs in another thread, whereas in a browser the setTimeout() interrupts the main thread and runs there. A problem (in regards to compatibility) which i'm having is that a setTimeout() callback can call arbitrary functions. Those functions might (directly or indirectly) use v8::Unlocker, which would give the main thread another chance at pre-empting the setTimeout callback. i've finally got the idea that i can work around this by putting TWO lockers in the pthread callback. e.g. it currently looks like: static void * thread_setTimeout( void * arg ) { if( ! v8::V8::IsDead() ) { v8::Locker locker; v8::HandleScope hsc; ... now if the callback uses Unlocker, the main thread (or another thread) can interrupt me. If, however, i change that to: v8::Locker locker; v8::Locker locker2; v8::HandleScope hsc; am i right in saying that even if a callback uses Unlocker, that the callback's thread will still have the lock? Obviously, it breaks if some code buried in the callback violates the Locker API and uses too many Unlockers, but i'm counting on v8's internal checking to catch that (i.e. crash during testing) long before such code is ever used via setTimeout(). Is that a viable workaround to my problem? If not, could someone suggest an idea of how i might be able to implement setTimeout() such that it runs in the main thread (but after the specified timeout)? i am not very thread-savvy, and haven't found a way to do that. :-? -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users To unsubscribe, reply using "remove me" as the subject.
