I think you need to specify better what semantics you intend. What is that "main" thread? Traditionally, in JS there is no main(), no piece of JS ever runs continuously or gets interrupted. Even the "initially" executing script needs to terminate before a setTimeout script will run. Once you realize that, you only ever need one thread that executes the event handlers / timeouts and "setTimeout" just needs to push them onto some priority queue.
Add to that I/O events and you've arrived at node.js (http://nodejs.org) Matthias On Tue, Apr 6, 2010 at 10:52 PM, Stephan Beal <[email protected]> wrote: > On Apr 6, 10:49 pm, Stephan Beal <[email protected]> wrote: > > If, however, i change that to: > > > > v8::Locker locker; > > v8::Locker locker2; > > v8::HandleScope hsc; > > to partially answer, but not entirely invalidate my question: i now > see that i would need the second locker (if my hypothesis is correct) > in a different location. > > The entire code is: > static void * thread_setTimeout( void * arg ) > { > #define THREAD_RETURN return NULL; //::pthread_exit( (void *)0 ) > if( ! v8::V8::IsDead() ) > { > v8::Locker locker; > v8::HandleScope hsc; > Detail::js_thread_info * jio = > reinterpret_cast<Detail::js_thread_info*>( arg ); > /** reminder: copy jio to the stack so we can free it up > immediately > and not worry about a leak via an exception > propagating below... */ > const Detail::js_thread_info ji(*jio); > const uint32_t udelay = ji.delay * 1000; > delete jio; > bool isFunc = ji.jv->IsFunction(); > typedef v8::Local<v8::Function> LoF; > LoF fh( ( isFunc ) ? > LoF( v8::Function::Cast( *(ji.jv) ) ) : LoF() ); > typedef v8::Local<v8::Value> LoS; > LoS jscode( (isFunc) ? LoS() : *(ji.jv) ); > do > { > int src = 0; > { > v8::Unlocker ul; > /** > FIXME: for long waits, wake up periodically and see > if > we should still be waiting, otherwise this might > keep > the app from exiting from an arbitrarily long time > after the main thread has gone. But how to know > that? > */ > /** > FIXME: posix has obsoleted usleep() and > recommends > nanonosleep(), with it's much more complicated > interface. OTOH, according to APUE, nanosleep() > is only > required to be defined on platforms which > implement "the > real-time extensions". What to do? > */ > src = ::usleep( udelay ); > // Check for cancellation resp. unregister the > timer ID: > Detail::TimerLock lock; > if( ! (ji.isInterval ? lock.has(ji.id) : > lock.take(ji.id)) ) break; > } > if( v8::V8::IsDead() ) break; > if( isFunc ) > { > ----------> NEW v8::Locker lock2; > fh->Call( ji.jself, 0, 0 ); > } > else > { > ----------> NEW v8::Locker lock2; > ji.evalfunc->Call( ji.jself, 1, &jscode ); > } > } while( ji.isInterval ); > } > THREAD_RETURN; > #undef THREAD_RETURN > } > > > Would that solve the problem i'm having? > > -- > v8-users mailing list > [email protected] > http://groups.google.com/group/v8-users > > To unsubscribe, reply using "remove me" as the subject. > -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users
