The ms you set is used here:
void ContextSwitcher::Run() {
while (keep_going_) {
OS::Sleep(sleep_ms_);
isolate()->stack_guard()->Preempt();
}
}
So what you're doing basically is to preempt on every preemptible point.
There might be a better way of doing this without the need of a thread
constantly setting the PREEMPT flag on the current StackGuard instance
(several times actually). May be to set the flag ON by default on the
StackGuard constructor.
Anyway, it's interesting indeed as that would be the fairest
distribution possible from an engine perspective, may be somebody from
the engine team can tell us more accurately what's the overhead involved
in a preemption task switch.
pablo.
On 07/02/2012 04:34 PM, Michael Schwartz wrote:
> You might find this interesting.
>
> I tried setting preemption time to 10ms and output of my script was sporadic
> (in bursts). I set it to 1ms and it got way better. I set it to 0ms and it
> seems perfect.
>
> I'm not sure what kind of performance impact this setting has.
>
> On Jul 2, 2012, at 10:52 AM, Pablo Sole wrote:
>
>> On 07/02/2012 01:00 PM, Michael Schwartz wrote:
>>> Wow, that's a great tip. I implemented it and long running threads work
>>> fine and get preempted.
>> Glad to help!
>>> I guess the disadvantage is thread safety and synchronization of data
>>> accesses. I'm not clear on when a thread running in v8 might be preempted.
>>> Likely on entering or exiting functions (when doing stack checks, I think
>>> I remember reading about).
>> AFAIK, any StackGuard instance is preemptible, regex matching also check
>> for preemption, some loops and there must be some other places too. This
>> mechanism is used by chromium, I suppose, to switch between Contexts
>> (frames/iframes) of a same tab (Isolate?). I'm completely making this up
>> and it's probably not accurate, but must be something like that :).
>>
>> The rule of thumb for thread safety should be to not trust on a Locker
>> instance (which can be preempted) for any resource sync managed or
>> potentially modified from outside of v8. A C++ function wrapped inside a
>> FunctionTemplate though, cannot be preempted of course, so that's safe.
>>
>> pablo.
>>
>> --
>> v8-users mailing list
>> [email protected]
>> http://groups.google.com/group/v8-users
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users