I have some code which uses the current SequencedTaskRunnerHandle to implement behavior similar to PostTaskAndReply, i.e. it does async work and then replies to the caller on the original calling sequence.In this case however, it is imperative that the reply task block shutdown. I have not found any way to accomplish this with our current scheduling APIs. Am I missing something?
For more context, the reply callback here will always have a base::SequenceBound<T> argument whose target TaskRunner is shutdown-blocking. This means that if shutdown completes before the reply task can execute, the SequencedBound will be destroyed after shutdown has completed. This will result in it attempting to post a shutdown-blocking task (to run ~T) after doing so is no longer allowed.
--
You received this message because you are subscribed to the Google Groups "scheduler-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scheduler-de...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/scheduler-dev/CA%2BapAgFk44DbkwpnMViNWbxZHZuFbcix_cBOaTUuwHP9adGqDA%40mail.gmail.com.
Le mar. 16 févr. 2021 20 h 33, 'Ken Rockot' via scheduler-dev <schedu...@chromium.org> a écrit :I have some code which uses the current SequencedTaskRunnerHandle to implement behavior similar to PostTaskAndReply, i.e. it does async work and then replies to the caller on the original calling sequence.In this case however, it is imperative that the reply task block shutdown. I have not found any way to accomplish this with our current scheduling APIs. Am I missing something?If you post a BLOCK_SHUTDOWN task (e.g. your reply) from within another BLOCK_SHUTDOWN task, it is guaranteed to extend shutdown.Caveats :1) ShutdownBehavior is associated with a task runner, not an individual task. This is to avoid having non blocking tasks that surprisingly become blocking when sequenced ahead of blocking tasks.2) ShutdownBehavior is only supported by ThreadPool task runners (via base::TaskTraits). This is because BrowserThread::UI never runs again once shutdown is initiated (I've thought of changing that but it's been like this since Chrome v1) and BrowserThread::IO is Thread::Join()'ed on shutdown so effectively BLOCK_SHUTDOWN already.That being said if the task runner you get from SequencedTaskRunnerHandle is BLOCK_SHUTDOWN, so will your reply be.
For more context, the reply callback here will always have a base::SequenceBound<T> argument whose target TaskRunner is shutdown-blocking. This means that if shutdown completes before the reply task can execute, the SequencedBound will be destroyed after shutdown has completed. This will result in it attempting to post a shutdown-blocking task (to run ~T) after doing so is no longer allowed.Now that's quite interesting. SequenceBound is one of the first widely used constructs that implicitly posts on destruction... This breaks the assertions built in to ThreadPool that try to prevent posting BLOCK_SHUTDOWN after Shutdown() as this catches ordering mistakes that would surprisingly result in a BLOCK_SHUTDOWN task not running.This is the first time I hear about this limitation caused by ~SequenceBound. Do you actually need to run ~T? Maybe we could add Leaky traits to SequenceBound?+Daniel Cheng ^^?
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/scheduler-dev/CA%2BapAgE%2BjgHBHnDcJ6Buz3QT7GL3oGbshT7%3DcFw8fViFXRWM7A%40mail.gmail.com.
On Wed, Feb 17, 2021 at 4:57 AM Gabriel Charette <g...@chromium.org> wrote:Le mar. 16 févr. 2021 20 h 33, 'Ken Rockot' via scheduler-dev <schedu...@chromium.org> a écrit :I have some code which uses the current SequencedTaskRunnerHandle to implement behavior similar to PostTaskAndReply, i.e. it does async work and then replies to the caller on the original calling sequence.In this case however, it is imperative that the reply task block shutdown. I have not found any way to accomplish this with our current scheduling APIs. Am I missing something?If you post a BLOCK_SHUTDOWN task (e.g. your reply) from within another BLOCK_SHUTDOWN task, it is guaranteed to extend shutdown.Caveats :1) ShutdownBehavior is associated with a task runner, not an individual task. This is to avoid having non blocking tasks that surprisingly become blocking when sequenced ahead of blocking tasks.2) ShutdownBehavior is only supported by ThreadPool task runners (via base::TaskTraits). This is because BrowserThread::UI never runs again once shutdown is initiated (I've thought of changing that but it's been like this since Chrome v1) and BrowserThread::IO is Thread::Join()'ed on shutdown so effectively BLOCK_SHUTDOWN already.That being said if the task runner you get from SequencedTaskRunnerHandle is BLOCK_SHUTDOWN, so will your reply be.Right, unfortunately in this case the SequencedTaskRunnerHandle is acquired at an arbitrary point before the initial shutdown-blocking task is posted.
--For more context, the reply callback here will always have a base::SequenceBound<T> argument whose target TaskRunner is shutdown-blocking. This means that if shutdown completes before the reply task can execute, the SequencedBound will be destroyed after shutdown has completed. This will result in it attempting to post a shutdown-blocking task (to run ~T) after doing so is no longer allowed.Now that's quite interesting. SequenceBound is one of the first widely used constructs that implicitly posts on destruction... This breaks the assertions built in to ThreadPool that try to prevent posting BLOCK_SHUTDOWN after Shutdown() as this catches ordering mistakes that would surprisingly result in a BLOCK_SHUTDOWN task not running.This is the first time I hear about this limitation caused by ~SequenceBound. Do you actually need to run ~T? Maybe we could add Leaky traits to SequenceBound?+Daniel Cheng ^^?Yeah, a leaky SequenceBound is sufficient in this case. I've already made this one leaky by wrapping it with a sometimes-leaked unique_ptr, but I was hoping for a cleaner approach. :)I suppose the rationale here is that if you allow distinct per-task TaskShutdownBehavior, you will occasionally need to violate (or complicate) the sequencing guarantees of the API?--
You received this message because you are subscribed to the Google Groups "scheduler-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scheduler-de...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/scheduler-dev/CA%2BapAgFk44DbkwpnMViNWbxZHZuFbcix_cBOaTUuwHP9adGqDA%40mail.gmail.com.
You received this message because you are subscribed to the Google Groups "scheduler-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scheduler-de...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/scheduler-dev/CA%2BapAgE%2BjgHBHnDcJ6Buz3QT7GL3oGbshT7%3DcFw8fViFXRWM7A%40mail.gmail.com.
So is it the case that the TaskRunner to which the PostTaskAndReply task is being posted is _not_ shutdown-blocking? Only the reply TaskRunner is?
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/scheduler-dev/CALekkJdq41okvwa-Si6rrsja1WvEXbjS-CCDYoGW2121q3q%3DEg%40mail.gmail.com.
Le mer. 17 févr. 2021 10 h 59, 'Ken Rockot' via scheduler-dev <schedu...@chromium.org> a écrit :On Wed, Feb 17, 2021 at 4:57 AM Gabriel Charette <g...@chromium.org> wrote:Le mar. 16 févr. 2021 20 h 33, 'Ken Rockot' via scheduler-dev <schedu...@chromium.org> a écrit :I have some code which uses the current SequencedTaskRunnerHandle to implement behavior similar to PostTaskAndReply, i.e. it does async work and then replies to the caller on the original calling sequence.In this case however, it is imperative that the reply task block shutdown. I have not found any way to accomplish this with our current scheduling APIs. Am I missing something?If you post a BLOCK_SHUTDOWN task (e.g. your reply) from within another BLOCK_SHUTDOWN task, it is guaranteed to extend shutdown.Caveats :1) ShutdownBehavior is associated with a task runner, not an individual task. This is to avoid having non blocking tasks that surprisingly become blocking when sequenced ahead of blocking tasks.2) ShutdownBehavior is only supported by ThreadPool task runners (via base::TaskTraits). This is because BrowserThread::UI never runs again once shutdown is initiated (I've thought of changing that but it's been like this since Chrome v1) and BrowserThread::IO is Thread::Join()'ed on shutdown so effectively BLOCK_SHUTDOWN already.That being said if the task runner you get from SequencedTaskRunnerHandle is BLOCK_SHUTDOWN, so will your reply be.Right, unfortunately in this case the SequencedTaskRunnerHandle is acquired at an arbitrary point before the initial shutdown-blocking task is posted.Timing shouldn't matter. The task runner is always or never BLOCK_SHUTDOWN.
Le mer. 17 févr. 2021 12 h 31, Wez <w...@chromium.org> a écrit :So is it the case that the TaskRunner to which the PostTaskAndReply task is being posted is _not_ shutdown-blocking? Only the reply TaskRunner is?My understanding is both are shutdown-blocking. Otherwise it definitely won't work.
On Wed, Feb 17, 2021 at 10:53 AM Gabriel Charette <g...@chromium.org> wrote:Le mer. 17 févr. 2021 12 h 31, Wez <w...@chromium.org> a écrit :So is it the case that the TaskRunner to which the PostTaskAndReply task is being posted is _not_ shutdown-blocking? Only the reply TaskRunner is?My understanding is both are shutdown-blocking. Otherwise it definitely won't work.Looking at the implementation:- the PostTask task runner is whatever you ask for - if you provide BLOCK_SHUTDOWN, it will block shutdown- the reply task runner just SequencedTaskRunnerHandle::Get(), at the time PostTaskAndReply is calledSo in general the two task runners are determined independently, and therefore so is the shutdown-blocking behavior of each task. I don't see any guarantee that both are either shutdown-blocking or not.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/scheduler-dev/CA%2BapAgHtgfYSi9K%2BrAsM3C0YhQorbB%3Dc3oprbUivQE_md4cUow%40mail.gmail.com.
It seems that we need a special-case for requests to delete objects on shutdown-blocking sequences during/after shutdown - perhaps that's what you meant by a "leaky" trait, Gab?
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/scheduler-dev/CALekkJde%2BQ0R1hBtyeG2HC43Hc5YXASLWyknSrXRtGhxSAu9bQ%40mail.gmail.com.