SequencedTaskRunner semantics

36 views
Skip to first unread message

Sunny Sachanandani

unread,
Jun 23, 2015, 5:56:58 PM6/23/15
to Chromium-dev, brian...@chromium.org, Tim Ansell
Hi,

I have a question about SequencedTaskRunner semantics. What is the ordering of two (non-nestable) tasks posted sequentially like this (in the same message loop iteration / call stack):

PostDelayedTask(T1, 1us);
PostTask(T2); (equivalent to PostDelayedTask(T2, 0))

Intuitively I would think that T2 will run before T1. The comments about sequenced task runner on this matter are a little vague. In particular I'm not sure if it should say "if and only if" instead of "if" in this excerpt:

//   - Given two tasks T2 and T1, T2 will start after T1 starts if:
//
//       * T2 is posted after T1; and
//       * T2 has equal or higher delay than T1; and
//       * T2 is non-nestable or T1 is nestable.

Looking at some task runner implementations it seems that MessageLoopTaskRunner and LibDispatchTaskRunner behave like I described above. Some of the test task runners like OrderedSimpleTaskRunner do not behave this way.

Let me know if there's something that I'm missing. Thanks!

- Sunny

Alex Clarke

unread,
Jun 24, 2015, 5:09:44 AM6/24/15
to sun...@chromium.org, Tim Ansell, chromium-dev, brian...@chromium.org

I'm under the impression that T2 should run first always in that scenario.

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

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.

Gabriel Charette

unread,
Jul 6, 2015, 8:17:01 AM7/6/15
to alexc...@google.com, sun...@chromium.org, Tim Ansell, brian...@chromium.org, chromium-dev

Which one runs first is undefined in this scenario.

The moment T1 is posted, the posting thread could be de-scheduled and T1 could be processed by a worker thread before T2 is even posted (this is less and less likely the bigger T1's delay but is never impossible). Even if the posting thread and underlying thread of the SequencedTaskRunner are the same, the delay could have passed by the time a task is dequeued).

Of course T2 could also run first per its smaller delay if posted and processed in time.

The only difference between SequencedTaskRunner and TaskRunner in this scenario is that both tasks are guaranteed to run in sequence (i.e. not in parallel).

Hope this makes sense, happy to answer follow-up questions.

Gab

Reply all
Reply to author
Forward
0 new messages