Skip to content

Commit 48b9805

Browse files
committed
Add CloseDefaultThreadPool
1 parent a37887c commit 48b9805

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

onnxruntime/test/onnx/main.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff 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
353352
int wmain(int argc, wchar_t* argv[]) {
354353
#else
355354
int 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
}

onnxruntime/test/onnx/sync_api.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ using ORT_CALLBACK_FUNCTION = PTP_WORK_CALLBACK;
2323
inline PThreadPool GetDefaultThreadPool(const ::onnxruntime::Env&) {
2424
return nullptr;
2525
}
26+
inline void CloseDefaultThreadPool() {}
2627
#else
2728
#define ORT_CALLBACK
2829
namespace Eigen {
@@ -38,10 +39,11 @@ using ORT_CALLBACK_INSTANCE = OnnxRuntimeCallbackInstance*;
3839
using ORT_CALLBACK_FUNCTION = void ORT_CALLBACK (*)(ORT_CALLBACK_INSTANCE pci, void* context, ORT_WORK work);
3940
//Do nothing
4041
inline void OnnxRuntimeCloseThreadpoolWork(ORT_WORK) {}
41-
#endif
42-
42+
void CloseDefaultThreadPool();
4343
//The returned value will be used with CreateAndSubmitThreadpoolWork function
4444
PThreadPool 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

onnxruntime/test/onnx/sync_api_linux.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
6670
Status OnnxRuntimeSetEventWhenCallbackReturns(ORT_CALLBACK_INSTANCE pci, ORT_EVENT finish_event) {
6771
if (finish_event == nullptr)
6872
return Status(onnxruntime::common::ONNXRUNTIME, onnxruntime::common::INVALID_ARGUMENT, "");

0 commit comments

Comments
 (0)