MCPcopy Create free account
hub / github.com/davisking/dlib / shutdown_pool

Method shutdown_pool

dlib/threads/thread_pool_extension.cpp:32–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30// ----------------------------------------------------------------------------------------
31
32 void thread_pool_implementation::
33 shutdown_pool (
34 )
35 {
36 {
37 auto_mutex M(m);
38
39 // first wait for all pending tasks to finish
40 bool found_task = true;
41 while (found_task)
42 {
43 found_task = false;
44 for (unsigned long i = 0; i < tasks.size(); ++i)
45 {
46 // If task bucket i has a task that is currently supposed to be processed
47 if (tasks[i].is_empty() == false)
48 {
49 found_task = true;
50 break;
51 }
52 }
53
54 if (found_task)
55 task_done_signaler.wait();
56 }
57
58 // now tell the threads to kill themselves
59 we_are_destructing = true;
60 task_ready_signaler.broadcast();
61 }
62
63 // wait for all threads to terminate
64 for (auto& t : threads)
65 t.join();
66 threads.clear();
67
68 // Throw any unhandled exceptions. Since shutdown_pool() is only called in the
69 // destructor this will kill the program.
70 for (auto&& task : tasks)
71 task.propagate_exception();
72 }
73
74// ----------------------------------------------------------------------------------------
75

Callers

nothing calls this directly

Calls 6

sizeMethod · 0.45
is_emptyMethod · 0.45
waitMethod · 0.45
broadcastMethod · 0.45
clearMethod · 0.45
propagate_exceptionMethod · 0.45

Tested by

no test coverage detected