while (!tmp_s.empty()) {
pair app = tmp_s.top(); tmp_s.pop();
priority_list.push(app);
rate[i] = min(total_resources, max_resource_list[map_task_num[app.first]]);
tasklist[app.first]->resource_rate = rate[i];
tasklist[app.first]->predict_left_time = predict_left_list[i][rate[i] / 5 ];
total_resources -= rate[i];
char buf[10];
sprintf(buf, "%d%d", map_task_num[app.first], rate[i] * 1000);
pthread_t t;
pthread_create(&t, NULL, preempted, (void *)buf);
pthread_detach(t);
}
主线程传入字符串,但是由于该字符串是局部变量,当子线程接收到字符串后,但是由于主线程执行完该函数,释放了局部变量,因此子线程接收到的指针变成野指针。
void * preempted(void * arg) {
char *curr = (char *)arg;
}
解决办法:
1、子线程接收到该字符串后,通过strcpy复制一份
2、主线程改变该局部变量的生命周期(例如改为静态局部变量)



