modify threads
This commit is contained in:
BIN
LFtid1056.rar
BIN
LFtid1056.rar
Binary file not shown.
@@ -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或者在补招,继续补招处理
|
||||
|
||||
@@ -678,8 +678,9 @@ void cleanup_args(ThreadArgs* args) {
|
||||
}
|
||||
|
||||
void* cloudfrontthread(void* arg) {
|
||||
///////////////////////////////////////
|
||||
ThreadArgs* args = static_cast<ThreadArgs*>(arg);
|
||||
|
||||
//不再需要入参20251208
|
||||
/*ThreadArgs* args = static_cast<ThreadArgs*>(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;
|
||||
}
|
||||
|
||||
|
||||
@@ -232,17 +232,93 @@ void* message_processor_thread(void* arg) {
|
||||
}
|
||||
/* <20>߳<EFBFBD><DFB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
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; // <20><><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>֮ǰ<D6AE><C7B0> STOPPED<45><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD> tid <20>ǿգ<C7BF><D5A3><EFBFBD><EFBFBD>Ի<EFBFBD><D4BB><EFBFBD>һ<EFBFBD>¾<EFBFBD><C2BE>̣߳<DFB3><CCA3><EFBFBD>ֹ<EFBFBD><D6B9>Դй¶<D0B9><C2B6>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);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> join<69><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>
|
||||
if (old_tid) {
|
||||
pthread_join(old_tid, NULL);
|
||||
}
|
||||
|
||||
// ========== <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD> ==========lnk20251208
|
||||
if (index == 0) {
|
||||
// <20>ӿ<EFBFBD> + MQ<4D><51>cloudfrontthread <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>Ӵ<EFBFBD> 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) {
|
||||
// <20>ͻ<EFBFBD><CDBB>˹<EFBFBD><CBB9><EFBFBD><EFBFBD>߳<EFBFBD>
|
||||
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); // ʧ<>ܲ<EFBFBD><DCB2>Լ<EFBFBD> free<65><65><EFBFBD>ɹ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>߳<EFBFBD><DFB3><EFBFBD> free
|
||||
}
|
||||
} else if (index == 2) {
|
||||
// <20><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>
|
||||
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 {
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD><DFB3>ݲ<EFBFBD><DDB2><EFBFBD><EFBFBD><EFBFBD>
|
||||
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);
|
||||
}
|
||||
|
||||
/*// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>
|
||||
int* new_index = (int*)malloc(sizeof(int));
|
||||
*new_index = index;
|
||||
|
||||
@@ -268,21 +344,22 @@ void restart_thread(int index) {
|
||||
}
|
||||
else if (index == 0) {
|
||||
// <20>ӿڣ<D3BF>mq
|
||||
char* argv[] = { (char*)new_index };//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̺Ų<CCBA><C5B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
ThreadArgs* args = new ThreadArgs{1, argv};
|
||||
if (pthread_create(&thread_info[index].tid, NULL, cloudfrontthread, args) != 0) {
|
||||
//char* argv[] = { (char*)new_index };//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̺Ų<CCBA><C5B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// 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; // <20><><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6>ͷ<EFBFBD>
|
||||
//delete args; // <20><><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6>ͷ<EFBFBD>
|
||||
free(new_index);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>գ<EFBFBD>ʵ<EFBFBD><CAB5>Ӧ<EFBFBD><D3A6><EFBFBD>п<EFBFBD><D0BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
/* <20>̴߳<DFB3><CCB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
@@ -291,14 +368,14 @@ int is_thread_alive(pthread_t tid) {
|
||||
}
|
||||
|
||||
//lnk<6E><6B><EFBFBD><EFBFBD>
|
||||
ThreadArgs* make_thread_args_from_strs(const std::vector<std::string>& args_vec) {
|
||||
/*ThreadArgs* make_thread_args_from_strs(const std::vector<std::string>& args_vec) {
|
||||
char** argv = new char*[args_vec.size() + 1]; // <20><>һ<EFBFBD><D2BB> nullptr <20><>β
|
||||
for (size_t i = 0; i < args_vec.size(); ++i) {
|
||||
argv[i] = strdup(args_vec[i].c_str()); // strdup <20><> malloc <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
argv[args_vec.size()] = nullptr;
|
||||
return new ThreadArgs{static_cast<int>(args_vec.size()), argv};
|
||||
}
|
||||
}*/
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
int main(int argc ,char** argv) {//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD>
|
||||
@@ -317,10 +394,10 @@ int main(int argc ,char** argv) {//
|
||||
}
|
||||
|
||||
//<2F>ӿں<D3BF>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){
|
||||
|
||||
BIN
稳定性问题调查.docx
Normal file
BIN
稳定性问题调查.docx
Normal file
Binary file not shown.
Reference in New Issue
Block a user