[webkit-dev] WTF::callOnMainThread() and re-entrancy

Alexey Proskuryakov ap at webkit.org
Tue Mar 9 11:13:14 PST 2010

On 09.03.2010, at 9:45, Drew Wilson wrote:

> Yeah, it's a race condition - it seems to all depend on whether the  
> worker resource gets loaded before the postMessage loop starts.  
> Failure rate is around 30-50% on my machine.

It would help to have a more detailed description of the problem. I've  
been following the discussion in bugs and in this thread, but I'm  
still unsure about some aspects of it.

Seems that there are two issues at hand:

1) We feel the need to change how Document::postTask() behaves,  
because otherwise, the patch for <https://bugs.webkit.org/show_bug.cgi?id=34726 
 > doesn't work. We feel the need because it makes little sense for it  
to have drastically different behavior depending on what thread it's  
called from.

It feels like a good change to make indeed, but I'm surprised that it  
apparently went through review unmentioned and unquestioned. The  
questions to ask are why exactly it was needed, and whether there are  
other ways to fix bug 34726.

2) if we make that change, the worker-cloneport.html test starts to  

I didn't attempt to debug this myself, and I don't quite understand  
the problem description. I see only one postMessage loop in the test,  
and it's in worker code. How can it be executed before the worker  
resource gets loaded?

> It looks like events have priority in Cocoa, and I'm guessing that  
> performSelectorOnMainThread() creates events with a higher priority  
> than those generated by URLConnection, which can lead to starvation.  
> I'm not certain what the right fix is, other than to maybe use a  
> different method of dispatching events other than  
> performSelectorOnMainThread that lets us set a lower priority?

These main thread calls do not use events for processing. CF/NSRunLoop  
has a concept of run loop sources, which can generate events or  
perform other actions, see <http://developer.apple.com/mac/library/documentation/CoreFoundation/Reference/CFRunLoopRef/Reference/reference.html 
 > and <http://developer.apple.com/Mac/library/documentation/CoreFoundation/Reference/CFRunLoopSourceRef/Reference/reference.html 

- WBR, Alexey Proskuryakov

More information about the webkit-dev mailing list