我的VC++ 2010快速安裝的時間在工作,已經過期,所以我不能再使用它,而不改變從右下的日期。我不想這樣做,所以我問你這些問題:簡單線程的順序
你認爲,在多線程程序的線程下面的順序工作?
如果我把類似的3多個線程計算下一個1000粒子,情景開關會耗盡還是睡眠(10)正在用盡?
注意:每個計算(。的力的每一個,VEL,POS)約需9毫秒。
Something like this:
core1:first 1000 particles forces //
core2:first 1000 particles velocities //===>these 3 are connected
core3:first 1000 particles positions // ------------------------------
|
core4:next 1000 particles forces // ====these 2 will be connected
core5:next 1000 particles velocities //===>these 3 are connected |
core6:next 1000 particles positions // ------------------------------
boolean locker1;
boolean locker2;
boolean locker3;
boolean worker1;
boolean worker2;
boolean worker3;
void core1(void * x)
{
while(worker1)
{
while(!locker1){Sleep(10);}
for(int i=0;i<1000;i++)
{
//calculate 1000 particles forces
}
locker2=true; //starts core2 thread
while(locker2){Sleep(10);} //core2 must be working
while(locker3){Sleep(10);} //core3 must be working
}
_endthread();
}
void core2(void * y)
{
while(worker2)
{
if(!locker2){Sleep(10);}
for(int i=0;i<1000;i++)
{
//calculate 1000 particles velocities
}
locker3=true; //starts core3 thread
while(locker3){Sleep(10);} //core3 must be working
while(locker1){Sleep(10);} //core1 must be working
}
_endthread();
}
void core3(void * z)
{
while(worker3)
{
if(!locker3){Sleep(10);}
for(int i=0;i<1000;i++)
{
//calculate 1000 particles positions
}
locker1=true; //starts core1 thread
while(locker1){Sleep(10);} //core1 must be working
while(locker2){Sleep(10);} //core2 must be working
}
_endthread();
}
int main()
{
locker1=false;
locker2=false;
locker3=false;
worker1=true;
worker2=true;
worker3=true;
_beginthread(core1,0,(void *)0);
_beginthread(core2,0,(void *)0);
_beginthread(core3,0,(void *)0);
locker1=true; //gets the waiting core1-thread working
//so i think when it finishes, it releases core2 to work
//when core2 finishes, core3 starts working
Sleep(100);
worker1=false;
worker2=false;
worker3=false; //after a while i shut them down
}
請如果有任何人有VC++可以給我一些提示或建議我欣賞。
Or should i just forget the 3+3-->2 system and do this(6)? :
core1 first 233 particles for computing forces ----->all for velocity ----->all for psoition
core2 next 233 particles for computing forces ----->all for velocity ----->all for psoition
core3 next 233 particles for computing forces ----->all for velocity ----->all for psoition
core4 next 233 particles for computing forces ----->all for velocity ----->all for psoition
core5 next 233 particles for computing forces ----->all for velocity ----->all for psoition
core6 last 233 particles for computing forces ----->all for velocity ----->all for psoition
and just wait all of them finish to get to next calculation?
你是要我們寫和分析你的應用程序? –
您是否知道只需註冊Visual C++ 2010 Express即可在30天后繼續使用它?我的安裝已經超過兩年了,工作正常... – Blastfurnace
:O我不知道。我以爲需要錢 –