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

Method threader

dlib/threads/threads_kernel_shared.cpp:66–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64// ----------------------------------------------------------------------------------------
65
66 threader::
67 threader (
68 ) :
69 total_count(0),
70 function_pointer(0),
71 pool_count(0),
72 data_ready(data_mutex),
73 data_empty(data_mutex),
74 destruct(false),
75 destructed(data_mutex),
76 do_not_ever_destruct(false)
77 {
78#ifdef WIN32
79 // Trying to destroy the global thread pool when we are part of a DLL and the
80 // DLL is being unloaded can sometimes lead to weird behavior. For example, in
81 // the python interpreter you will get the interpreter to hang. Or if we are
82 // part of a MATLAB mex file and the file is being unloaded there can also be
83 // similar weird issues. So when we are using dlib on windows we just disable
84 // the destruction of the global thread pool since it doesn't matter anyway.
85 // It's resources will just get freed by the OS. This is even the recommended
86 // thing to do by Microsoft (http://blogs.msdn.com/b/oldnewthing/archive/2012/01/05/10253268.aspx).
87 //
88 // As an aside, it's worth pointing out that the reason we try and free
89 // resources on program shutdown on other operating systems is so we can have
90 // clean reports from tools like valgrind which check for memory leaks. But
91 // trying to do this on windows is a lost cause so we give up in this case and
92 // follow the Microsoft recommendation.
93 do_not_ever_destruct = true;
94#endif // WIN32
95 }
96
97// ----------------------------------------------------------------------------------------
98

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected