18 {
19 while (
state.KeepRunning()) {
21
22 const int num_task_queues = 10;
23 const int num_tasks_per_queue = 100;
25
26 for (
int i = 0;
i < num_task_queues;
i++) {
27 task_queue->CreateTaskQueue();
28 }
29
30 std::vector<std::thread> threads;
31
34
35 threads.reserve(num_task_queues);
36 for (
int i = 0;
i < num_task_queues;
i++) {
37 threads.emplace_back([task_runner_id =
i, &task_queue, past, &tasks_done,
38 &tasks_registered]() {
39 for (int j = 0; j < num_tasks_per_queue; j++) {
40 task_queue->RegisterTask(
TaskQueueId(task_runner_id), [] {}, past);
41 }
42 tasks_registered.CountDown();
43 tasks_registered.Wait();
45 int num_invocations = 0;
46 for (;;) {
48 task_queue->GetNextTaskToRun(TaskQueueId(task_runner_id), now);
49 if (!invocation) {
50 break;
51 }
52 num_invocations++;
53 }
54 assert(num_invocations == num_tasks_per_queue);
55 tasks_done.CountDown();
56 });
57 }
58
59 tasks_done.Wait();
60
61 for (auto& thread : threads) {
62 thread.join();
63 }
64 }
65}
static MessageLoopTaskQueues * GetInstance()
std::function< void()> closure