In callOnMainThreadAndWait, if MainThreadFunction finishes before the wait is entered, then the sync() call has no effect. (Thanks to Alexey for pointing out the same problem elsewhere.)
Created attachment 27606 [details] Patch for bug.
It would be nice to change callOnMainThread function to match the same style too (remove local scope for the mutex and needToSchedule variable).
Comment on attachment 27606 [details] Patch for bug. Retracting while I consider dimich's suggestion.
Created attachment 27623 [details] Patch to remove unused function. callOnMainThreadAndWait isn't used and it has a race in it.
Comment on attachment 27623 [details] Patch to remove unused function. r=me Seems to me we can add a version without the race if we find we need it for something.
Committed revision 40969.