File tree Expand file tree Collapse file tree 3 files changed +12
-5
lines changed Expand file tree Collapse file tree 3 files changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -346,18 +346,19 @@ int real_main(int argc, char* argv[]) {
346346 result = -1 ;
347347 }
348348 }
349-
350349 return result;
351350}
352351#ifdef _WIN32
353352int wmain (int argc, wchar_t * argv[]) {
354353#else
355354int main (int argc, char * argv[]) {
356355#endif
356+ int ret = -1 ;
357357 try {
358- return real_main (argc, argv);
358+ ret = real_main (argc, argv);
359359 } catch (std::exception& ex) {
360360 fprintf (stderr, " %s\n " , ex.what ());
361- return -1 ;
362361 }
362+ CloseDefaultThreadPool ();
363+ return ret;
363364}
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ using ORT_CALLBACK_FUNCTION = PTP_WORK_CALLBACK;
2323inline PThreadPool GetDefaultThreadPool (const ::onnxruntime::Env&) {
2424 return nullptr ;
2525}
26+ inline void CloseDefaultThreadPool () {}
2627#else
2728#define ORT_CALLBACK
2829namespace Eigen {
@@ -38,10 +39,11 @@ using ORT_CALLBACK_INSTANCE = OnnxRuntimeCallbackInstance*;
3839using ORT_CALLBACK_FUNCTION = void ORT_CALLBACK (*)(ORT_CALLBACK_INSTANCE pci, void * context, ORT_WORK work);
3940// Do nothing
4041inline void OnnxRuntimeCloseThreadpoolWork (ORT_WORK) {}
41- #endif
42-
42+ void CloseDefaultThreadPool ();
4343// The returned value will be used with CreateAndSubmitThreadpoolWork function
4444PThreadPool GetDefaultThreadPool (const ::onnxruntime::Env& env);
45+ #endif
46+
4547// On Windows, the last parameter can be null, in that case it will use the default thread pool.
4648// On Linux, there is no per process default thread pool. You have to pass a non-null pointer.
4749// Caller must delete the data pointer if this function returns a non-ok status. Otherwise, the ownership is transferred
Original file line number Diff line number Diff line change @@ -63,6 +63,10 @@ PThreadPool GetDefaultThreadPool(const onnxruntime::Env& env) {
6363 return default_pool.get ();
6464}
6565
66+ void CloseDefaultThreadPool () {
67+ default_pool.reset ();
68+ }
69+
6670Status OnnxRuntimeSetEventWhenCallbackReturns (ORT_CALLBACK_INSTANCE pci, ORT_EVENT finish_event) {
6771 if (finish_event == nullptr )
6872 return Status (onnxruntime::common::ONNXRUNTIME, onnxruntime::common::INVALID_ARGUMENT, " " );
You can’t perform that action at this time.
0 commit comments