怎样将C++代码改为多线程?
# include "dayin.h"
int main()
{
.........
dayin(B,C);
.........
return 0;
}
////////////////////////
dayin(int B, int C)
{
for(int i=B,i<C,i++)
{
//--------------------------------代码区一
int a=0,b=0,c=0;
for(int j=0,j<100,j++)
{
.........//耗时的不同运算
a= ;//a,b,c的值改变
b= ;
c= ;
.........
}
cout<<a+b+c<<endl;//1
//--------------------------------代码区二
a=0,b=0,c=0;
for( j=0,j<100,j++)
{
.........//耗时的不同运算
a= ;//a,b,c的值改变
b= ;
c= ;
.........
}
cout<<a+b+c<<endl;//2
//--------------------------------代码区三
a=0,b=0,c=0;
for( j=0,j<100,j++)
{
.........//耗时的不同运算
a= ;//a,b,c的值改变
b= ;
c= ;
.........
}
cout<<a+b+c<<endl;//3
}
return 0;
}
我想把代码区一、二、三分别改为三个线程函数,同时运行,
但是:
cout<<a+b+c<<endl;//1
cout<<a+b+c<<endl;//2
cout<<a+b+c<<endl;//3
这三处cout,按1、2、3的顺序分别打印。
请问,怎样改为多线程?谢谢!