如线程
void thread(...){
while(1){
...
result=calculate();
if(result>GloBestResult){
GloBestResult=result;
}
}
}
建立多个线程加快速度,但是如GloBestResult=1,
线程a和b计算的result分别为2和3匀大于GloBestResult,而b线先改动GloBestReult
然后轮到线程a,那3这个结果就被覆盖了。
怎么解决,加入信号量吗?会不会杀鸡用宰牛刀了,毕竟冲突的情况是极少数,信号量申请那可是上百万次。
不太想分别统计各个线程的BestResult最后再汇总到GloBestResult