PostTask question

47 views
Skip to first unread message

all smooth

unread,
May 20, 2013, 6:30:57 PM5/20/13
to chromi...@chromium.org
If PostTask happens to the same thread, seems the task cannot be automatically started, and I have to take care of sub-pump. Question is how to start sub-pump?

The detailed scenarios:

IO Thread starts:
1. Create URLRequest
2. my code kicks in to start URLFetcher, pl notice this happened in the same IO thread. 
 2.1 start a new URLRequest, this request will be added to IO thread queue again. which introduces additional task must be finished before first URLRequest finished.
 2.2 need to pump this sub-pump to get it done first. Then how?

thanks,
all smooth


Ryan Sleevi

unread,
May 20, 2013, 6:38:51 PM5/20/13
to guang...@gmail.com, Chromium-dev
Don't.

Really, you don't want to use run loops.

Your code (the code initializing the URLFetcher) should yield control
if the underlying function is pending. The message loop will, once IO
has happened, notify the underlying transport socket, which will
bubble up through to the transport & URLRequest layers, which will
ultimately notify your URLRequest (or more aptly, its delegate) of
progress.
> --
> --
> Chromium Developers mailing list: chromi...@chromium.org
> View archives, change email options, or unsubscribe:
> http://groups.google.com/a/chromium.org/group/chromium-dev
>
>
>

all smooth

unread,
May 20, 2013, 6:50:34 PM5/20/13
to chromi...@chromium.org, guang...@gmail.com, rsl...@chromium.org
That's the problem. I didnot get any notification from my delegate.  So I guess it's because the sub-pump issue since I initialize the URLFetcher in io thread, and this is different from major usage in chrome. In chrome URLFetcher init is through main GUI thread. Besides, seems there is no related http request send it out physically from my network sniffer.

Ryan Sleevi

unread,
May 20, 2013, 6:54:35 PM5/20/13
to all smooth, Chromium-dev
You still need to ensure the underlying MessageLoop is pumped, but you
should not be doing this as a "sub-pump"

For example, base::Thread will pump its associated MessageLoop
whenever the currently running Task is completed.

You should (generally) never need to pump yourself - abstractions like
base::Thread handle that.

all smooth

unread,
May 20, 2013, 7:29:19 PM5/20/13
to chromi...@chromium.org, all smooth, rsl...@chromium.org
OK, I believe I should not start own message run. However, the samethread_messageloop->PostTask to the same thread does hurt or not? Seems the task is not scheduled and executed at all.

Ryan Sleevi

unread,
May 20, 2013, 7:31:57 PM5/20/13
to all smooth, Chromium-dev, Ryan Sleevi
If your MessageLoop is running (eg: *somewhere* on your stack, you've
got a MessageLoop::Run() frame), PostTask will cause it to be run when
the message pump turns. Unless you're Quit()ing the message loop
before then.

all smooth

unread,
May 20, 2013, 8:29:14 PM5/20/13
to chromi...@chromium.org, all smooth, Ryan Sleevi
Thanks for all replies. It's my own coding problem to skip the task because of pre-mature release the fetcher pointer.
all smooth,
Reply all
Reply to author
Forward
0 new messages