PostTaskAndReply Pattern for BlockingPool Tasks?

23 views
Skip to first unread message

Mike Rossetti

unread,
May 29, 2012, 7:16:55 PM5/29/12
to chromium-dev
I've got some database update code that is using PostSequencedWorkerTask(...) calls for queuing up the various database updates.

Is there a pattern for notifying the posting thread (i.e. the main thread) that kicked off all of these updates once all of them have completed? Something similar to PostTaskAndReply?

What I'd like to do is to queue up all of these sequenced tasks and then post one final sequenced task that then does the reply call back to the main thread.

All advice will be appreciated!
Mike

William Chan (陈智昌)

unread,
May 29, 2012, 7:23:21 PM5/29/12
to mros...@chromium.org, chromium-dev
The blocking pool is a derived class of TaskRunner which provides a PostTaskAndReply() member function. You can probably build on top of this by having the reply closures share the necessary state (a counter or whatever) and run another closure when all the reply closures have completed.

Mike

--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev

William Chan (陈智昌)

unread,
May 29, 2012, 7:24:33 PM5/29/12
to mros...@chromium.org, chromium-dev
Oh, I see now that you're using sequenced tasks. You can get a SequencedTaskRunner from the SequencedWorkerPool::GetSequencedTaskRunner(SequencedToken) member function. SequencedTaskRunner, as a derived class of TaskRunner, has a PostTaskAndReply() member function.

Darin Fisher

unread,
May 29, 2012, 7:26:26 PM5/29/12
to will...@chromium.org, mros...@chromium.org, chromium-dev
... and you can fire off an additional PostTaskAndReply that will be guaranteed to run after all of the other tasks have run.  This might be easier than maintaining a counter.

-Darin

Mike Rossetti

unread,
May 29, 2012, 7:51:28 PM5/29/12
to Darin Fisher, will...@chromium.org, chromium-dev
Awesome! Thanks William and Darin! I'll grab a runner and use the PostTaskAndReply. Slick.

Mike
Reply all
Reply to author
Forward
0 new messages