なぜなのでしょうか? また、この問題を回避するにはどうすればいいのでしょうか?
#include<stdio.h>
#include<time.h>
#include<windows.h>
#include<process.h>
void syori(void);
unsigned __stdcall another(){
syori();
printf("anotherスレッドの処理が終わりました\n");
return 0;
}
void syori(){
int a,b;
unsigned long i;
for(a=i=0;a<=35;a++)
for(b=0;b<=0xfffffff;b++) i++;
printf("%u\n",i);
}
int main()
{
clock_t start,end;
DWORD thread;
HANDLE handle;
//並列処理を使ったときの時間を計測
start=clock();
handle=(HANDLE)_beginthreadex(NULL,0,another,NULL,0,(unsigned int *)&thread);//別のスレッドを立てる
syori();
WaitForSingleObject((void *)thread, INFINITE);//ここで別のスレッドが終わるまで待ってくれるはず
end=clock();
printf("並列処理は%f秒\n\n",(double)(end-start)/CLOCKS_PER_SEC);//時間の表示
//通常の処理のときの時間を計測
start=clock();
syori();
syori();
end=clock();
printf("通常の処理は%f秒\n",(double)(end-start)/CLOCKS_PER_SEC);//時間の表示
_endthreadex((unsigned)handle);
CloseHandle(handle);
return 0;
}