幽淆 发表于 2025-11-1 12:30:20

批量多进程创建

错误方式:

创建第一个线程时,该线程来不及保存namebuffer的数据就切换到主线程
然后主线程修改namebuffer准备创建第二个线程,而导致前一个线程还未
保存的数据被第二个线程的数据所覆盖了,导致最后输出多个线程的内容一样
且有部分线程输出内容缺失
#include#include#include#include#includeusing namespace std;//新线程,函数被多个线程调用:重入状态void *thread_routine(void *args){    string name = static_cast(args);    while(true){      cout
页: [1]
查看完整版本: 批量多进程创建