G
Guest
Hi! I wrote this simple program in C++ (I'm studying some C++ applied to the
windows enviroinment) that creates a child thread:
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <math.h>
#define MAX_THREADS 1
int j,k;
DWORD WINAPI threadfunc(LPVOID param)
{
for(int i=0;i<100000000;i++)
{
sin(rand()*2*3.1412);
j++;
}
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE t = CreateThread(NULL,0,threadfunc,NULL,0,NULL);
for(int i=0;i<100;i++)
{
cos(rand()*2*3.1412);
k++;
}
WaitForMultipleObjects(MAX_THREADS,&t,TRUE,INFINITE);
printf("Ok, done!%d,%d\n",j,k);
}
The two threads are perfectly synchronized, but... I noticed that the CPU
usage is only 50%! My CPU is an AMD Athlon64 X2 3800+, and I'm using windows
xp pro sp2. Do I have to set some particular optimization in the project
properties panel?
Thank you in advance!
windows enviroinment) that creates a child thread:
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <math.h>
#define MAX_THREADS 1
int j,k;
DWORD WINAPI threadfunc(LPVOID param)
{
for(int i=0;i<100000000;i++)
{
sin(rand()*2*3.1412);
j++;
}
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE t = CreateThread(NULL,0,threadfunc,NULL,0,NULL);
for(int i=0;i<100;i++)
{
cos(rand()*2*3.1412);
k++;
}
WaitForMultipleObjects(MAX_THREADS,&t,TRUE,INFINITE);
printf("Ok, done!%d,%d\n",j,k);
}
The two threads are perfectly synchronized, but... I noticed that the CPU
usage is only 50%! My CPU is an AMD Athlon64 X2 3800+, and I'm using windows
xp pro sp2. Do I have to set some particular optimization in the project
properties panel?
Thank you in advance!