Dear List Members,
I ran into a question in a code review [1] where I couldn't find a definitive answer from the documentation at [2]. The question is essentially whether or not the following is safe:
class A {
public:
A()
: task_runner_(base::CreateSequencedTaskRunnerWithTraits(
{base::TaskPriority::USER_VISIBLE})) {}
~A() = default;
void SomeMethod() {
task_runner_->PostTask(FROM_HERE,
base::BindOnce(&A::SomeMethodToBeRunOnTaskRunner,
base::Unretained(this)));
}
void SomeMethodToBeRunOnTaskRunner() {
// ...
}
private:
scoped_refptr<base::SequencedTaskRunner> task_runner_;
};
This basically comes down to whether or not releasing |task_runner_| created via
CreateSequencedTaskRunnerWithTraits would guarantee to block while the posted
task is executing and guarantee to discard the task if it had not yet started
executing. My assumption is that it does not give any such guarantee, but I
realize that it could be implemented this way.