On Mon, May 25, 2009 at 2:58 PM, Book'em Dano <[email protected]> wrote:
> MessageLoop::PostTask() runs a method asynchronously within a
> destination thread. The problem I have is that I'd like to execute
> this code (on the destination thread) synchronously.
>
> More details: I'm using a NotificationService on a worker thread
> (which uses TLS), so I need to proxy the call to add/remove observers
> from the main thread over to the worker thread. To do this, I'm
> calling PostTask to invoke the add/remove observer code on the work
> thread. I want/need to block the main thread though until the add/
> remove observer code has actually been processed by the worker
> thread.

I agree with Adam -- this won't work.

A few notes that might point you in the right direction:
- If you're working on a data structure that truly is shared with the
main thread, then a lock is the appropriate thing.  In general, we
avoid locks and use message passing instead, and because of that we
avoid data structures that are shared.  Search for "AutoLock" in the
code.
- The Notification service most definitely is designed to only work on
the UI thread.  It and its users assume notifications happen on one
thread and synchronously.

If you're trying to catch a notification that needs to get to a worker
thread, a pattern we use elsewhere is to have an object that lives on
the UI thread that gets the notification then makes an async call over
to the worker thread.  You have to be careful about the relative
lifetimes of the objects involved, but it can be done.  Take a look at
the greasemonkey master class (I think?) or maybe the FileWatcher
class.

--~--~---------~--~----~------------~-------~--~----~
Chromium Developers mailing list: [email protected] 
View archives, change email options, or unsubscribe: 
    http://groups.google.com/group/chromium-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to