Commit f340e7ffb2e98ce20c87c24f5325bef26d8040c5
1 parent
940c8179
将由运行时库来清理线程,修改为由代码主动结束线程,避免可能的资源浪费
Showing
2 changed files
with
11 additions
and
5 deletions
tsl_aiplatform/reprocessing_module/save_snapshot_reprocessing.cpp
@@ -10,6 +10,7 @@ const bool DRAW_ON_IMG = false; | @@ -10,6 +10,7 @@ const bool DRAW_ON_IMG = false; | ||
10 | 10 | ||
11 | vector<int> compression_params; | 11 | vector<int> compression_params; |
12 | DWORD save_image_thread_process(LPVOID param); | 12 | DWORD save_image_thread_process(LPVOID param); |
13 | +bool bFinish = false; | ||
13 | 14 | ||
14 | map<int, algo_type> index_to_algo_type = {{0, algorithm_type_t::HUMAN_SNAPSHOT}, | 15 | map<int, algo_type> index_to_algo_type = {{0, algorithm_type_t::HUMAN_SNAPSHOT}, |
15 | {1, algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT}, | 16 | {1, algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT}, |
@@ -35,14 +36,18 @@ save_snapshot_reprocessing::save_snapshot_reprocessing() { | @@ -35,14 +36,18 @@ save_snapshot_reprocessing::save_snapshot_reprocessing() { | ||
35 | _task_param_manager = task_param_manager::getInstance(); | 36 | _task_param_manager = task_param_manager::getInstance(); |
36 | 37 | ||
37 | bFinish = false; | 38 | bFinish = false; |
38 | - auto m_save_ss_thread = std::thread(save_image_thread_process, this); | ||
39 | - m_save_ss_thread.detach(); | 39 | + m_save_ss_thread = std::thread(save_image_thread_process, this); |
40 | + // m_save_ss_thread.detach(); | ||
40 | } | 41 | } |
41 | 42 | ||
42 | -// 释放资源 | ||
43 | -void save_snapshot_reprocessing::save_snapshot_reprocessing_release() { | 43 | +save_snapshot_reprocessing::~save_snapshot_reprocessing(){ |
44 | // 结束线程 | 44 | // 结束线程 |
45 | bFinish = true; | 45 | bFinish = true; |
46 | + m_save_ss_thread.join(); | ||
47 | +} | ||
48 | + | ||
49 | +// 释放资源 | ||
50 | +void save_snapshot_reprocessing::save_snapshot_reprocessing_release() { | ||
46 | 51 | ||
47 | std::unique_lock<std::mutex> l(waitforsave_image_queue_mutex); | 52 | std::unique_lock<std::mutex> l(waitforsave_image_queue_mutex); |
48 | 53 |
tsl_aiplatform/reprocessing_module/save_snapshot_reprocessing.h
@@ -55,6 +55,7 @@ class save_snapshot_reprocessing : public base_reprocessing_unit | @@ -55,6 +55,7 @@ class save_snapshot_reprocessing : public base_reprocessing_unit | ||
55 | { | 55 | { |
56 | public: | 56 | public: |
57 | save_snapshot_reprocessing(); | 57 | save_snapshot_reprocessing(); |
58 | + ~save_snapshot_reprocessing(); | ||
58 | void save_snapshot_reprocessing_release(); | 59 | void save_snapshot_reprocessing_release(); |
59 | 60 | ||
60 | void add_newtask(const string taskid); | 61 | void add_newtask(const string taskid); |
@@ -82,7 +83,7 @@ public: | @@ -82,7 +83,7 @@ public: | ||
82 | // map<OBJ_KEY, int> save_snapshot_info_count; // debug by zsh | 83 | // map<OBJ_KEY, int> save_snapshot_info_count; // debug by zsh |
83 | mutable std::mutex waitforchange_taskid_mutex; | 84 | mutable std::mutex waitforchange_taskid_mutex; |
84 | 85 | ||
85 | - bool bFinish{false}; | 86 | + std::thread m_save_ss_thread; |
86 | 87 | ||
87 | #ifdef POST_USE_RABBITMQ | 88 | #ifdef POST_USE_RABBITMQ |
88 | callback_t callback_; | 89 | callback_t callback_; |