diff --git a/LFtid1056.rar b/LFtid1056.rar index 3444c11..8cc4b0b 100644 Binary files a/LFtid1056.rar and b/LFtid1056.rar differ diff --git a/LFtid1056/cloudfront/code/cfg_parser.cpp b/LFtid1056/cloudfront/code/cfg_parser.cpp index 5b391c5..793054b 100644 --- a/LFtid1056/cloudfront/code/cfg_parser.cpp +++ b/LFtid1056/cloudfront/code/cfg_parser.cpp @@ -4415,7 +4415,7 @@ void check_recall_event() { } } - if (had_items_before && popped_any && lm.recall_list.empty()) {//处理后,当前测点补招记录为空 + if (had_items_before && popped_any && lm.recall_list.empty()) {//处理后,当前测点补招记录为空 //通知补招全部完成 std::cout << "[check_recall_event] finish recall monitor=" << lm.monitor_id << std::endl; //读取记录文件获取响应参数 @@ -4480,7 +4480,6 @@ void check_recall_event() { dev.busytimecount = 0; // 计时归零 continue; //处理完处理下一个装置 } - //有待补招任务,且idle或者在补招,继续补招处理 diff --git a/LFtid1056/cloudfront/code/main.cpp b/LFtid1056/cloudfront/code/main.cpp index 524dd23..b138f5e 100644 --- a/LFtid1056/cloudfront/code/main.cpp +++ b/LFtid1056/cloudfront/code/main.cpp @@ -678,8 +678,9 @@ void cleanup_args(ThreadArgs* args) { } void* cloudfrontthread(void* arg) { -/////////////////////////////////////// - ThreadArgs* args = static_cast(arg); + + //不再需要入参20251208 + /*ThreadArgs* args = static_cast(arg); int argc = args->argc; char **argv = args->argv; @@ -697,7 +698,9 @@ void* cloudfrontthread(void* arg) { std::cerr << "[cloudfrontthread] Failed to parse index from argv[0]: " << argv[0] << "\n"; return nullptr; } - } + }*/ + (void)arg; + const int index = 0; // 更新线程状态为运行中 pthread_mutex_lock(&thread_info[index].lock); @@ -705,8 +708,7 @@ void* cloudfrontthread(void* arg) { thread_info[index].state = THREAD_RUNNING; pthread_mutex_unlock(&thread_info[index].lock); -/////////////////////////////////////// - // 解析命令行参数 + /*// 解析命令行参数 if(!parse_param(argc,argv)){ std::cerr << "process param error,exit" << std::endl; cleanup_args(args); @@ -714,7 +716,7 @@ void* cloudfrontthread(void* arg) { } // 线程使用完后清理参数 - cleanup_args(args); + cleanup_args(args);*/ //路径获取 FRONT_PATH = get_parent_directory(); @@ -787,6 +789,12 @@ void* cloudfrontthread(void* arg) { std::this_thread::sleep_for(std::chrono::seconds(60));//每分钟检测一次 } + // 退出前标记为 STOPPED,方便监控线程判断并重启 + pthread_mutex_lock(&thread_info[index].lock); + thread_info[index].state = THREAD_STOPPED; + printf("cloudfrontthread %d stopped\n", index); + pthread_mutex_unlock(&thread_info[index].lock); + return nullptr; } diff --git a/LFtid1056/main_thread.cpp b/LFtid1056/main_thread.cpp index 36059f7..15589ba 100644 --- a/LFtid1056/main_thread.cpp +++ b/LFtid1056/main_thread.cpp @@ -232,17 +232,93 @@ void* message_processor_thread(void* arg) { } /* ߳ */ void restart_thread(int index) { + + //lnk20251208 + pthread_t old_tid = 0; + pthread_mutex_lock(&global_lock); + if (thread_info[index].state == THREAD_RESTARTING) { pthread_mutex_unlock(&global_lock); return; // ظ } + // ֮ǰ STOPPED tid ǿգԻһ¾ֹ̣߳Դй¶lnk20251208 + if (thread_info[index].state == THREAD_STOPPED && thread_info[index].tid) { + old_tid = thread_info[index].tid; + thread_info[index].tid = 0; + } + thread_info[index].state = THREAD_RESTARTING; + printf("Restarting thread %d\n", index); + pthread_mutex_unlock(&global_lock); - // ߳ + // join߳ + if (old_tid) { + pthread_join(old_tid, NULL); + } + + // ========== ߳ ==========lnk20251208 + if (index == 0) { + // ӿ + MQcloudfrontthread ҪֱӴ NULL + if (pthread_create(&thread_info[index].tid, NULL, + cloudfrontthread, NULL) != 0) { + pthread_mutex_lock(&global_lock); + printf("Failed to restart cloudfrontthread %d\n", index); + thread_info[index].state = THREAD_CRASHED; + pthread_mutex_unlock(&global_lock); + } + } else if (index == 1) { + // ͻ˹߳ + int* new_index = (int*)malloc(sizeof(int)); + if (!new_index) { + pthread_mutex_lock(&global_lock); + printf("Failed to malloc for client manager thread %d\n", index); + thread_info[index].state = THREAD_CRASHED; + pthread_mutex_unlock(&global_lock); + return; + } + *new_index = index; + + if (pthread_create(&thread_info[index].tid, NULL, + client_manager_thread, new_index) != 0) { + pthread_mutex_lock(&global_lock); + printf("Failed to restart client manager thread %d\n", index); + thread_info[index].state = THREAD_CRASHED; + pthread_mutex_unlock(&global_lock); + free(new_index); // ʧܲԼ freeɹʱ߳ free + } + } else if (index == 2) { + // Ϣ߳ + int* new_index = (int*)malloc(sizeof(int)); + if (!new_index) { + pthread_mutex_lock(&global_lock); + printf("Failed to malloc for message processor thread %d\n", index); + thread_info[index].state = THREAD_CRASHED; + pthread_mutex_unlock(&global_lock); + return; + } + *new_index = index; + + if (pthread_create(&thread_info[index].tid, NULL, + message_processor_thread, new_index) != 0) { + pthread_mutex_lock(&global_lock); + printf("Failed to restart message processor thread %d\n", index); + thread_info[index].state = THREAD_CRASHED; + pthread_mutex_unlock(&global_lock); + free(new_index); + } + } else { + // ߳ݲ + pthread_mutex_lock(&global_lock); + printf("Thread %d is not configured for restart\n", index); + thread_info[index].state = THREAD_CRASHED; + pthread_mutex_unlock(&global_lock); + } + + /*// ߳ int* new_index = (int*)malloc(sizeof(int)); *new_index = index; @@ -268,21 +344,22 @@ void restart_thread(int index) { } else if (index == 0) { // ӿڣmq - char* argv[] = { (char*)new_index };//Ҫ̺Ų - ThreadArgs* args = new ThreadArgs{1, argv}; - if (pthread_create(&thread_info[index].tid, NULL, cloudfrontthread, args) != 0) { + //char* argv[] = { (char*)new_index };//Ҫ̺Ų + // ThreadArgs* args = new ThreadArgs{1, argv}; + if (pthread_create(&thread_info[index].tid, NULL, cloudfrontthread, new_index) != 0) { pthread_mutex_lock(&global_lock); printf("Failed to restart message processor thread %d\n", index); thread_info[index].state = THREAD_CRASHED; pthread_mutex_unlock(&global_lock); - delete args; // ߳ûɹֶͷ + //delete args; // ߳ûɹֶͷ free(new_index); } } else { // ߳ // ΪգʵӦп߳ - } + }*/ + } /* ̴߳ */ @@ -291,14 +368,14 @@ int is_thread_alive(pthread_t tid) { } //lnk -ThreadArgs* make_thread_args_from_strs(const std::vector& args_vec) { +/*ThreadArgs* make_thread_args_from_strs(const std::vector& args_vec) { char** argv = new char*[args_vec.size() + 1]; // һ nullptr β for (size_t i = 0; i < args_vec.size(); ++i) { argv[i] = strdup(args_vec[i].c_str()); // strdup malloc } argv[args_vec.size()] = nullptr; return new ThreadArgs{static_cast(args_vec.size()), argv}; -} +}*/ /* */ int main(int argc ,char** argv) {//Ӳ @@ -317,10 +394,10 @@ int main(int argc ,char** argv) {// } //ӿںmq - ThreadArgs* args = make_thread_args_from_strs({ "0" }); - if (pthread_create(&thread_info[0].tid, NULL, cloudfrontthread, args) != 0) { + //ThreadArgs* args = make_thread_args_from_strs({ "0" }); + if (pthread_create(&thread_info[0].tid, NULL, cloudfrontthread, NULL) != 0) { printf("Failed to create message processor thread 0\n"); - cleanup_args(args); + //cleanup_args(args); } while(!INITFLAG){ diff --git a/稳定性问题调查.docx b/稳定性问题调查.docx new file mode 100644 index 0000000..879f1f1 Binary files /dev/null and b/稳定性问题调查.docx differ