Threading and Tasks in Chrome

Contents

Overview

Chromium is a very multithreaded product. We try to keep the UI as responsive as possible, and this means not blocking the UI thread with any blocking I/O or other expensive operations. Our approach is to use message passing as the way of communicating between threads. We discourage locking and threadsafe objects. Instead, objects live on only one thread, we pass messages between threads for communication, and we use callback interfaces (implemented by message passing) for most cross-thread requests.

Threads

Every Chrome process has

  • a main thread

    • in the browser process: updates the UI
    • in renderer processes: runs most of Blink
  • an IO thread
    • in the browser process: handles IPCs and network requests
    • in renderer processes: handles IPCs
  • a few more special-purpose threads
  • and a pool of general-purpose threads

Most threads have a loop that gets tasks from a queue and runs them (the queue may be shared between multiple threads).

Tasks

A task is a base::OnceClosure added to a queue for asynchronous execution.

base::OnceClosure stores a function pointer and arguments. It has a Run() method that invokes the function pointer using the bound arguments. It is created using base::BindOnce. (ref. Callback<> and Bind() documentation).

  1. void TaskA() {}
  2. void TaskB(int v) {}
  3.  
  4. auto task_a = base::BindOnce(&TaskA);
  5. auto task_b = base::BindOnce(&TaskB, 42);

A group of tasks can be executed in one of the following ways:

  • Parallel: No task execution ordering, possibly all at once on any thread
  • Sequenced: Tasks executed in posting order, one at a time on any thread.
  • Single Threaded: Tasks executed in posting order, one at a time on a single thread.

Prefer Sequences to Threads

Sequenced execution mode is far preferred to Single Threaded in scenarios that require mere thread-safety as it opens up scheduling paradigms that wouldn‘t be possible otherwise (sequences can hop threads instead of being stuck behind unrelated work on a dedicated thread). Ability to hop threads also means the thread count can dynamically adapt to the machine’s true resource availability (increased parallelism on bigger machines, avoids trashing resources on smaller machines).

Many core APIs were recently made sequence-friendly (classes are rarely thread-affine -- i.e. only when using thread-local-storage or third-party APIs that do). But the codebase has long evolved assuming single-threaded contexts... If your class could run on a sequence but is blocked by an overzealous use of ThreadChecker/ThreadTaskRunnerHandle/SingleThreadTaskRunner in a leaf dependency, consider fixing that dependency for everyone's benefit (or at the very least file a blocking bug against https://crbug.com/675631 and flag your use of base::CreateSingleThreadTaskRunnerWithTraits() with a TODO against your bug to use base::CreateSequencedTaskRunnerWithTraits() when fixed).

Detailed documentation on how to migrate from single-threaded contexts to sequenced contexts can be found here.

The discussion below covers all of these ways to execute tasks in details.

Posting a Parallel Task

Direct Posting to the Task Scheduler

A task that can run on any thread and doesn’t have ordering or mutual exclusion requirements with other tasks should be posted using one of the base::PostTask*() functions defined in base/task/post_task.h.

  1. base::PostTask(FROM_HERE, base::BindOnce(&Task));

This posts tasks with default traits.

The base::PostTask*WithTraits() functions allow the caller to provide additional details about the task via TaskTraits (ref. Annotating Tasks with TaskTraits).

  1. base::PostTaskWithTraits(
  2. FROM_HERE, {base::TaskPriority::BEST_EFFORT, MayBlock()},
  3. base::BindOnce(&Task));

Posting via a TaskRunner

A parallel TaskRunner is an alternative to calling base::PostTask*() directly. This is mainly useful when it isn’t known in advance whether tasks will be posted in parallel, in sequence, or to a single-thread (ref. Posting a Sequenced TaskPosting Multiple Tasks to the Same Thread). Since TaskRunner is the base class of SequencedTaskRunner and SingleThreadTaskRunner, a scoped_refptr<TaskRunner> member can hold a TaskRunner, a SequencedTaskRunner or a SingleThreadTaskRunner.

  1. class A {
  2. public:
  3. A() = default;
  4.  
  5. void set_task_runner_for_testing(
  6. scoped_refptr<base::TaskRunner> task_runner) {
  7. task_runner_ = std::move(task_runner);
  8. }
  9.  
  10. void DoSomething() {
  11. // In production, A is always posted in parallel. In test, it is posted to
  12. // the TaskRunner provided via set_task_runner_for_testing().
  13. task_runner_->PostTask(FROM_HERE, base::BindOnce(&A));
  14. }
  15.  
  16. private:
  17. scoped_refptr<base::TaskRunner> task_runner_ =
  18. base::CreateTaskRunnerWithTraits({base::TaskPriority::USER_VISIBLE});
  19. };

Unless a test needs to control precisely how tasks are executed, it is preferred to call base::PostTask*() directly (ref. Testing for less invasive ways of controlling tasks in tests).

Posting a Sequenced Task

A sequence is a set of tasks that run one at a time in posting order (not necessarily on the same thread). To post tasks as part of a sequence, use a SequencedTaskRunner.

Posting to a New Sequence

SequencedTaskRunner can be created by base::CreateSequencedTaskRunnerWithTraits().

  1. scoped_refptr<SequencedTaskRunner> sequenced_task_runner =
  2. base::CreateSequencedTaskRunnerWithTraits(...);
  3.  
  4. // TaskB runs after TaskA completes.
  5. sequenced_task_runner->PostTask(FROM_HERE, base::BindOnce(&TaskA));
  6. sequenced_task_runner->PostTask(FROM_HERE, base::BindOnce(&TaskB));

Posting to the Current Sequence

The SequencedTaskRunner to which the current task was posted can be obtained via SequencedTaskRunnerHandle::Get().

NOTE: it is invalid to call SequencedTaskRunnerHandle::Get() from a parallel task, but it is valid from a single-threaded task (a SingleThreadTaskRunner is a SequencedTaskRunner).
  1. // The task will run after any task that has already been posted
  2. // to the SequencedTaskRunner to which the current task was posted
  3. // (in particular, it will run after the current task completes).
  4. // It is also guaranteed that it won’t run concurrently with any
  5. // task posted to that SequencedTaskRunner.
  6. base::SequencedTaskRunnerHandle::Get()->
  7. PostTask(FROM_HERE, base::BindOnce(&Task));

Using Sequences Instead of Locks

Usage of locks is discouraged in Chrome. Sequences inherently provide thread-safety. Prefer classes that are always accessed from the same sequence to managing your own thread-safety with locks.

Thread-safe but not thread-affine; how so? Tasks posted to the same sequence will run in sequential order. After a sequenced task completes, the next task may be picked up by a different worker thread, but that task is guaranteed to see any side-effects caused by the previous one(s) on its sequence.

  1. class A {
  2. public:
  3. A() {
  4. // Do not require accesses to be on the creation sequence.
  5. DETACH_FROM_SEQUENCE(sequence_checker_);
  6. }
  7.  
  8. void AddValue(int v) {
  9. // Check that all accesses are on the same sequence.
  10. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  11. values_.push_back(v);
  12. }
  13.  
  14. private:
  15. SEQUENCE_CHECKER(sequence_checker_);
  16.  
  17. // No lock required, because all accesses are on the
  18. // same sequence.
  19. std::vector<int> values_;
  20. };
  21.  
  22. A a;
  23. scoped_refptr<SequencedTaskRunner> task_runner_for_a = ...;
  24. task_runner_for_a->PostTask(FROM_HERE,
  25. base::BindOnce(&A::AddValue, base::Unretained(&a), 42));
  26. task_runner_for_a->PostTask(FROM_HERE,
  27. base::BindOnce(&A::AddValue, base::Unretained(&a), 27));
  28.  
  29. // Access from a different sequence causes a DCHECK failure.
  30. scoped_refptr<SequencedTaskRunner> other_task_runner = ...;
  31. other_task_runner->PostTask(FROM_HERE,
  32. base::BindOnce(&A::AddValue, base::Unretained(&a), 1));

Locks should only be used to swap in a shared data structure that can be accessed on multiple threads. If one thread updates it based on expensive computation or through disk access, then that slow work should be done without holding on to the lock. Only when the result is available should the lock be used to swap in the new data. An example of this is in PluginList::LoadPlugins ([content/common/plugin_list.cc](https://cs.chromium.org/chromium/src/content/ common/plugin_list.cc). If you must use locks, here are some best practices and pitfalls to avoid.

In order to write non-blocking code, many APIs in Chromium are asynchronous. Usually this means that they either need to be executed on a particular thread/sequence and will return results via a custom delegate interface, or they take a base::Callback<> object that is called when the requested operation is completed. Executing work on a specific thread/sequence is covered in the PostTask sections above.

Posting Multiple Tasks to the Same Thread

If multiple tasks need to run on the same thread, post them to a SingleThreadTaskRunner. All tasks posted to the same SingleThreadTaskRunner run on the same thread in posting order.

Posting to the Main Thread or to the IO Thread in the Browser Process

To post tasks to the main thread or to the IO thread, use base::PostTaskWithTraits() or get the appropriate SingleThreadTaskRunner using base::CreateSingleThreadTaskRunnerWithTraits, supplying a BrowserThread::ID as trait. For this, you'll also need to include content/public/browser/browser_task_traits.h.

  1. base::PostTaskWithTraits(FROM_HERE, {content::BrowserThread::UI}, ...);
  2.  
  3. base::CreateSingleThreadTaskRunnerWithTraits({content::BrowserThread::IO})
  4. ->PostTask(FROM_HERE, ...);

The main thread and the IO thread are already super busy. Therefore, prefer posting to a general purpose thread when possible (ref. Posting a Parallel TaskPosting a Sequenced task). Good reasons to post to the main thread are to update the UI or access objects that are bound to it (e.g. Profile). A good reason to post to the IO thread is to access the internals of components that are bound to it (e.g. IPCs, network). Note: It is not necessary to have an explicit post task to the IO thread to send/receive an IPC or send/receive data on the network.

Posting to the Main Thread in a Renderer Process

TODO

Posting to a Custom SingleThreadTaskRunner

If multiple tasks need to run on the same thread and that thread doesn’t have to be the main thread or the IO thread, post them to a SingleThreadTaskRunner created by base::CreateSingleThreadTaskRunnerWithTraits.

  1. scoped_refptr<SequencedTaskRunner> single_thread_task_runner =
  2. base::CreateSingleThreadTaskRunnerWithTraits(...);
  3.  
  4. // TaskB runs after TaskA completes. Both tasks run on the same thread.
  5. single_thread_task_runner->PostTask(FROM_HERE, base::BindOnce(&TaskA));
  6. single_thread_task_runner->PostTask(FROM_HERE, base::BindOnce(&TaskB));
IMPORTANT: You should rarely need this, most classes in Chromium require thread-safety (which sequences provide) not thread-affinity. If an API you’re using is incorrectly thread-affine (i.e. using base::ThreadChecker when it’s merely thread-unsafe and should use base::SequenceChecker), please consider fixing it instead of making things worse by also making your API thread-affine.

Posting to the Current Thread

IMPORTANT: To post a task that needs mutual exclusion with the current sequence of tasks but doesn’t absolutely need to run on the current thread, use SequencedTaskRunnerHandle::Get() instead of ThreadTaskRunnerHandle::Get() (ref. Posting to the Current Sequence). That will better document the requirements of the posted task. In a single-thread task, SequencedTaskRunnerHandle::Get() is equivalent to ThreadTaskRunnerHandle::Get().

To post a task to the current thread, use ThreadTaskRunnerHandle.

  1. // The task will run on the current thread in the future.
  2. base::ThreadTaskRunnerHandle::Get()->PostTask(
  3. FROM_HERE, base::BindOnce(&Task));
NOTE: It is invalid to call ThreadTaskRunnerHandle::Get() from a parallel or a sequenced task.

Posting Tasks to a COM Single-Thread Apartment (STA) Thread (Windows)

Tasks that need to run on a COM Single-Thread Apartment (STA) thread must be posted to a SingleThreadTaskRunner returned by CreateCOMSTATaskRunnerWithTraits(). As mentioned in Posting Multiple Tasks to the Same Thread, all tasks posted to the same SingleThreadTaskRunner run on the same thread in posting order.

  1. // Task(A|B|C)UsingCOMSTA will run on the same COM STA thread.
  2.  
  3. void TaskAUsingCOMSTA() {
  4. // [ This runs on a COM STA thread. ]
  5.  
  6. // Make COM STA calls.
  7. // ...
  8.  
  9. // Post another task to the current COM STA thread.
  10. base::ThreadTaskRunnerHandle::Get()->PostTask(
  11. FROM_HERE, base::BindOnce(&TaskCUsingCOMSTA));
  12. }
  13. void TaskBUsingCOMSTA() { }
  14. void TaskCUsingCOMSTA() { }
  15.  
  16. auto com_sta_task_runner = base::CreateCOMSTATaskRunnerWithTraits(...);
  17. com_sta_task_runner->PostTask(FROM_HERE, base::BindOnce(&TaskAUsingCOMSTA));
  18. com_sta_task_runner->PostTask(FROM_HERE, base::BindOnce(&TaskBUsingCOMSTA));

Annotating Tasks with TaskTraits

TaskTraits encapsulate information about a task that helps the task scheduler make better scheduling decisions.

All PostTask*() functions in base/task/post_task.h have an overload that takes TaskTraits as argument and one that doesn’t. The overload that doesn’t take TaskTraits as argument is appropriate for tasks that:

  • Don’t block (ref. MayBlock and WithBaseSyncPrimitives).
  • Prefer inheriting the current priority to specifying their own.
  • Can either block shutdown or be skipped on shutdown (task scheduler is free to choose a fitting default). Tasks that don’t match this description must be posted with explicit TaskTraits.

base/task/task_traits.h provides exhaustive documentation of available traits. The content layer also provides additional traits in content/public/browser/browser_task_traits.h to facilitate posting a task onto a BrowserThread.

Below are some examples of how to specify TaskTraits.

  1. // This task has no explicit TaskTraits. It cannot block. Its priority
  2. // is inherited from the calling context (e.g. if it is posted from
  3. // a BEST_EFFORT task, it will have a BEST_EFFORT priority). It will either
  4. // block shutdown or be skipped on shutdown.
  5. base::PostTask(FROM_HERE, base::BindOnce(...));
  6.  
  7. // This task has the highest priority. The task scheduler will try to
  8. // run it before USER_VISIBLE and BEST_EFFORT tasks.
  9. base::PostTaskWithTraits(
  10. FROM_HERE, {base::TaskPriority::USER_BLOCKING},
  11. base::BindOnce(...));
  12.  
  13. // This task has the lowest priority and is allowed to block (e.g. it
  14. // can read a file from disk).
  15. base::PostTaskWithTraits(
  16. FROM_HERE, {base::TaskPriority::BEST_EFFORT, base::MayBlock()},
  17. base::BindOnce(...));
  18.  
  19. // This task blocks shutdown. The process won't exit before its
  20. // execution is complete.
  21. base::PostTaskWithTraits(
  22. FROM_HERE, {base::TaskShutdownBehavior::BLOCK_SHUTDOWN},
  23. base::BindOnce(...));
  24.  
  25. // This task will run on the Browser UI thread.
  26. base::PostTaskWithTraits(
  27. FROM_HERE, {content::BrowserThread::UI},
  28. base::BindOnce(...));

Keeping the Browser Responsive

Do not perform expensive work on the main thread, the IO thread or any sequence that is expected to run tasks with a low latency. Instead, perform expensive work asynchronously using base::PostTaskAndReply*() or SequencedTaskRunner::PostTaskAndReply(). Note that asynchronous/overlapped I/O on the IO thread are fine.

Example: Running the code below on the main thread will prevent the browser from responding to user input for a long time.

  1. // GetHistoryItemsFromDisk() may block for a long time.
  2. // AddHistoryItemsToOmniboxDropDown() updates the UI and therefore must
  3. // be called on the main thread.
  4. AddHistoryItemsToOmniboxDropdown(GetHistoryItemsFromDisk("keyword"));

The code below solves the problem by scheduling a call to GetHistoryItemsFromDisk() in a thread pool followed by a call to AddHistoryItemsToOmniboxDropdown() on the origin sequence (the main thread in this case). The return value of the first call is automatically provided as argument to the second call.

  1. base::PostTaskWithTraitsAndReplyWithResult(
  2. FROM_HERE, {base::MayBlock()},
  3. base::BindOnce(&GetHistoryItemsFromDisk, "keyword"),
  4. base::BindOnce(&AddHistoryItemsToOmniboxDropdown));

Posting a Task with a Delay

Posting a One-Off Task with a Delay

To post a task that must run once after a delay expires, use base::PostDelayedTask*() or TaskRunner::PostDelayedTask().

  1. base::PostDelayedTaskWithTraits(
  2. FROM_HERE, {base::TaskPriority::BEST_EFFORT}, base::BindOnce(&Task),
  3. base::TimeDelta::FromHours(1));
  4.  
  5. scoped_refptr<base::SequencedTaskRunner> task_runner =
  6. base::CreateSequencedTaskRunnerWithTraits({base::TaskPriority::BEST_EFFORT});
  7. task_runner->PostDelayedTask(
  8. FROM_HERE, base::BindOnce(&Task), base::TimeDelta::FromHours(1));
NOTE: A task that has a 1-hour delay probably doesn’t have to run right away when its delay expires. Specify base::TaskPriority::BEST_EFFORT to prevent it from slowing down the browser when its delay expires.

Posting a Repeating Task with a Delay

To post a task that must run at regular intervals, use base::RepeatingTimer.

  1. class A {
  2. public:
  3. ~A() {
  4. // The timer is stopped automatically when it is deleted.
  5. }
  6. void StartDoingStuff() {
  7. timer_.Start(FROM_HERE, TimeDelta::FromSeconds(1),
  8. this, &MyClass::DoStuff);
  9. }
  10. void StopDoingStuff() {
  11. timer_.Stop();
  12. }
  13. private:
  14. void DoStuff() {
  15. // This method is called every second on the sequence that invoked
  16. // StartDoingStuff().
  17. }
  18. base::RepeatingTimer timer_;
  19. };

Cancelling a Task

Using base::WeakPtr

base::WeakPtr can be used to ensure that any callback bound to an object is canceled when that object is destroyed.

  1. int Compute() { }
  2.  
  3. class A {
  4. public:
  5. A() : weak_ptr_factory_(this) {}
  6.  
  7. void ComputeAndStore() {
  8. // Schedule a call to Compute() in a thread pool followed by
  9. // a call to A::Store() on the current sequence. The call to
  10. // A::Store() is canceled when |weak_ptr_factory_| is destroyed.
  11. // (guarantees that |this| will not be used-after-free).
  12. base::PostTaskAndReplyWithResult(
  13. FROM_HERE, base::BindOnce(&Compute),
  14. base::BindOnce(&A::Store, weak_ptr_factory_.GetWeakPtr()));
  15. }
  16.  
  17. private:
  18. void Store(int value) { value_ = value; }
  19.  
  20. int value_;
  21. base::WeakPtrFactory<A> weak_ptr_factory_;
  22. };

Note: WeakPtr is not thread-safe: GetWeakPtr()~WeakPtrFactory(), and Compute() (bound to a WeakPtr) must all run on the same sequence.

Using base::CancelableTaskTracker

base::CancelableTaskTracker allows cancellation to happen on a different sequence than the one on which tasks run. Keep in mind that CancelableTaskTracker cannot cancel tasks that have already started to run.

  1. auto task_runner = base::CreateTaskRunnerWithTraits(base::TaskTraits());
  2. base::CancelableTaskTracker cancelable_task_tracker;
  3. cancelable_task_tracker.PostTask(task_runner.get(), FROM_HERE,
  4. base::DoNothing());
  5. // Cancels Task(), only if it hasn't already started running.
  6. cancelable_task_tracker.TryCancelAll();

Testing

To test code that uses base::ThreadTaskRunnerHandlebase::SequencedTaskRunnerHandle or a function in base/task/post_task.h, instantiate a base::test::ScopedTaskEnvironment for the scope of the test.

  1. class MyTest : public testing::Test {
  2. public:
  3. // ...
  4. protected:
  5. base::test::ScopedTaskEnvironment scoped_task_environment_;
  6. };
  7.  
  8. TEST(MyTest, MyTest) {
  9. base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, base::BindOnce(&A));
  10. base::SequencedTaskRunnerHandle::Get()->PostTask(FROM_HERE,
  11. base::BindOnce(&B));
  12. base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
  13. FROM_HERE, base::BindOnce(&C), base::TimeDelta::Max());
  14.  
  15. // This runs the (Thread|Sequenced)TaskRunnerHandle queue until it is empty.
  16. // Delayed tasks are not added to the queue until they are ripe for execution.
  17. base::RunLoop().RunUntilIdle();
  18. // A and B have been executed. C is not ripe for execution yet.
  19.  
  20. base::RunLoop run_loop;
  21. base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, base::BindOnce(&D));
  22. base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, run_loop.QuitClosure());
  23. base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, base::BindOnce(&E));
  24.  
  25. // This runs the (Thread|Sequenced)TaskRunnerHandle queue until QuitClosure is
  26. // invoked.
  27. run_loop.Run();
  28. // D and run_loop.QuitClosure() have been executed. E is still in the queue.
  29.  
  30. // Tasks posted to task scheduler run asynchronously as they are posted.
  31. base::PostTaskWithTraits(FROM_HERE, base::TaskTraits(), base::BindOnce(&F));
  32. auto task_runner =
  33. base::CreateSequencedTaskRunnerWithTraits(base::TaskTraits());
  34. task_runner->PostTask(FROM_HERE, base::BindOnce(&G));
  35.  
  36. // To block until all tasks posted to task scheduler are done running:
  37. base::TaskScheduler::GetInstance()->FlushForTesting();
  38. // F and G have been executed.
  39.  
  40. base::PostTaskWithTraitsAndReplyWithResult(
  41. FROM_HERE, base::TaskTrait(),
  42. base::BindOnce(&H), base::BindOnce(&I));
  43.  
  44. // This runs the (Thread|Sequenced)TaskRunnerHandle queue until both the
  45. // (Thread|Sequenced)TaskRunnerHandle queue and the TaskSchedule queue are
  46. // empty:
  47. scoped_task_environment_.RunUntilIdle();
  48. // E, H, I have been executed.
  49. }

Using TaskScheduler in a New Process

TaskScheduler needs to be initialized in a process before the functions in base/task/post_task.h can be used. Initialization of TaskScheduler in the Chrome browser process and child processes (renderer, GPU, utility) has already been taken care of. To use TaskScheduler in another process, initialize TaskScheduler early in the main function:

  1. // This initializes and starts TaskScheduler with default params.
  2. base::TaskScheduler::CreateAndStartWithDefaultParams(“process_name”);
  3. // The base/task/post_task.h API can now be used. Tasks will be // scheduled as
  4. // they are posted.
  5.  
  6. // This initializes TaskScheduler.
  7. base::TaskScheduler::Create(“process_name”);
  8. // The base/task/post_task.h API can now be used. No threads // will be created
  9. // and no tasks will be scheduled until after Start() is called.
  10. base::TaskScheduler::GetInstance()->Start(params);
  11. // TaskScheduler can now create threads and schedule tasks.

And shutdown TaskScheduler late in the main function:

  1. base::TaskScheduler::GetInstance()->Shutdown();
  2. // Tasks posted with TaskShutdownBehavior::BLOCK_SHUTDOWN and
  3. // tasks posted with TaskShutdownBehavior::SKIP_ON_SHUTDOWN that
  4. // have started to run before the Shutdown() call have now completed their
  5. // execution. Tasks posted with
  6. // TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN may still be
  7. // running.

TaskRunner ownership (encourage no dependency injection)

TaskRunners shouldn't be passed through several components. Instead, the components that uses a TaskRunner should be the one that creates it.

See this example of a refactoring where a TaskRunner was passed through a lot of components only to be used in an eventual leaf. The leaf can and should now obtain its TaskRunner directly from base/task/post_task.h.

Dependency injection of TaskRunners can still seldomly be useful to unit test a component when triggering a specific race in a specific way is essential to the test. For such cases the preferred approach is the following:

  1. class FooWithCustomizableTaskRunnerForTesting {
  2. public:
  3.  
  4. void SetBackgroundTaskRunnerForTesting(
  5. scoped_refptr<base::SequencedTaskRunner> background_task_runner);
  6.  
  7. private:
  8. scoped_refptr<base::SequencedTaskRunner> background_task_runner_ =
  9. base::CreateSequencedTaskRunnerWithTraits(
  10. {base::MayBlock(), base::TaskPriority::BEST_EFFORT});
  11. }

Note that this still allows removing all layers of plumbing between //chrome and that component since unit tests will use the leaf layer directly.

Threading and Tasks in Chrome的更多相关文章

  1. Tools that help you scrape web data----帮助你收集web数据的工具

    There are many programs that can be used to extract bulk information from a web site, including brow ...

  2. Thinking in Java——笔记(21)

    Concurrency However, becoming adept at concurrent programming theory and techniques is a step up fro ...

  3. VS Code 如何直接在浏览器中预览页面

    VS Code 预览html页面的时候,默认需要在资源管理器中显示,再在浏览器中预览.今天介绍一下如何直接预览html页面. 方法一:自己配置快捷键 1.ctrl + shift + p 或者 F1  ...

  4. [Python 多线程] Lock、阻塞锁、非阻塞锁 (八)

    线程同步技术: 解决多个线程争抢同一个资源的情况,线程协作工作.一份数据同一时刻只能有一个线程处理. 解决线程同步的几种方法: Lock.RLock.Condition.Barrier.semapho ...

  5. Code Project精彩系列(转)

    Code Project精彩系列(转)   Code Project精彩系列(转)   Applications Crafting a C# forms Editor From scratch htt ...

  6. Python中并发、多线程等

    1.基本概念 并发和并行的区别: 1)并行,parallel 同时做某些事,可以互不干扰的同一时刻做几件事.(解决并发的一种方法) 高速公路多个车道,车辆都在跑.同一时刻. 2)并发 concurre ...

  7. .Net多线程编程—System.Threading.Tasks.Parallel

    System.Threading.Tasks.Parallel类提供了Parallel.Invoke,Parallel.For,Parallel.ForEach这三个静态方法. 1 Parallel. ...

  8. Threading.Tasks 简单的使用

    using Lemon.Common; using System; using System.Collections.Generic; using System.Linq; using System. ...

  9. Threading.Tasks.Task多线程 静态全局变量(字典) --只为了记录

    --------------------------------------------------------------后台代码---------------------------------- ...

随机推荐

  1. 基于Zepto移动端下拉加载(刷新),上拉加载插件开发

    写在前面:本人水平有限,有什么分析不到位的还请各路大神指出,谢谢. 这次要写的东西是类似于<今日头条>的效果,下拉加载上啦加载,这次做的效果是简单的模拟,没有多少内容,下面是今日头条的移动 ...

  2. Android RecyclerView 设置item间隔的方法

    RecyclerView大家常用,但是如何给加载出来的item增加间隔很多人都不知道,下面是方法,直接上代码了: LinearLayoutManager layoutManager = new Lin ...

  3. RabbitMQ笔记(3)

    消息从产生--->结束 1.生产者--->交换机--->队列--->消费者 2.生产者--->交换机--->队列 首先: 生产者:Exchange = n:1 Ex ...

  4. sqlserver 恢复模式及避免日志爆满的方法

    recovery simple 循环日志,空间自动回收,不可备份日志,恢复时仅能恢复到数据库备份时间点: 用于落地数据或测试环境或OLAP,不推荐用于生产OLTP 有时候distribution过大也 ...

  5. JQuery插件的写法 (转:太棒啦!)

    JQuery插件写法的总结 最近Web应用程序中越来越多地用到了JQuery等Web前端技术.这些技术框架有效地改善了用户的操作体验,同时也提高了开发人员构造丰富客户 端UI的效率.JQuery本身提 ...

  6. Eclipse schema xml提示

    步骤一:确定xsd文件位置 spring-framework-3.2.0.RELEASE\schema\beans  步骤二:复制路径  步骤三:搜索“xml catalog”  步骤四:添加约束提示 ...

  7. HOJ 1867 经理的烦恼 【 树状数组 】

    题意:给出一个区间,求这个区间里面素数的个数 这道题wa了好多次---是因为add操作没有写对 每次更新的时候,应该先判断没有加上y是不是质数,加上了y是不是质数 如果从质数变成不是质数,那么add( ...

  8. IPv6理论知识详解

    1. IPv6地址表示 IPv6地址可以表示为128位由0.1组成的字符串,为了便于计算机理解,将128位的二进制字符串表示为32位的十六进制字符串,为了便于理解,人们将其划分为8组,组与组之间用 : ...

  9. IE模式下EasyUI Combobox无效问题

    近期开发过程中遇到IE浏览器Combobox无法正常加载问题. 经过一番百度说IE渲染过快导致页面渲染完了easyUI Combobox还没有加载.设置延迟加载后依旧无效. 后将input标签的Cla ...

  10. vux安装时报vux-loader配置问题

    一.初始化:webpack 项目塔建: 使用vue-cli塔建基于webpack的vue环境.然后根据vux官网安装使用文档安装vux组件库及配置build/webpack.base.conf.js. ...