[Greasemonkey] Re: Problems with 0.5.1

Nikolas Coukouma lists at atrus.org
Thu Sep 1 14:51:19 EDT 2005


Aaron Boodman wrote:
> On 9/1/05, Nikolas Coukouma <lists at atrus.org> wrote:
>   
>> There's a small race condition here; the document may load between the
>> time that the if statement is evaluated and before the listener is
>> added. This is unavoidable because JavaScript lacks synchronization. I
>> would suggest firing a load event, but then in-page scripts would see
>> two load events and that might screw with things.
>>     
>
> No, there isn't. JavaScript is single-threaded. The document may
> indeed finish loading, but the notification that it happened into
> javascript (onload) -- cannot preempt javascript that's already
> running.
>
> Actually in mozilla, amazing but true, there is basically one thread
> for everything. Even rendering and JS are on the same thread. The only
> things that are on separate threads are pretty obscure things like dns
> resolution, etc.
>   
The core of this is sort of like saying that single processor systems 
can't have race conditions. There's obviously a scheduler that switches 
between rendering, JS, etc. Perhaps you've talked to someone who knows 
how that works in Firefox (JS runs for a set time before yielding, 
statements/functions are atomic, and so on), but I certainly don't know. 
I know the spec doesn't promise anything. The most notable thing that 
suggests preemption is max_script_run_time.


More information about the Greasemonkey mailing list