J
james
Hi,all
Today i've met with a big problem. After compling the following
document, I entered 4 integers but cannot get what I want. how can I
modify it and get the result that I want? (input a,b,c,d and get m=a+b
+c+d , n=a*b*c*d).
Thanks in advance!
#include <windows.h>
#include <iostream.h>
#include <cstdlib>
int a,b,c,d;
int m,n;
DWORD WINAPI ThreadFunc1(HANDLE Thread1) //define thread1
{
m=a+b+c+d;
return 0;
}
DWORD WINAPI ThreadFunc2(HANDLE Thread2) //define thread2
{
n=a*b*c*d;
return 0;
}
int main() //main function
{
HANDLE Thread1;
HANDLE Thread2;
DWORD dwThreadId1;
DWORD dwThreadId2;
int a,b,c,d;
int m,n;
cout<<"please input a,b,c,d:"<<endl;
cin>>a>>b>>c>>d;
Thread1=::CreateThread //create thread1
(NULL,0,ThreadFunc1,NULL,0,&dwThreadId1);
Thread2=::CreateThread //create thread2 (NULL,
0,ThreadFunc2,NULL,0,&dwThreadId2);
::WaitForSingleObject(Thread1,INFINITE);
::CloseHandle(Thread1);
::WaitForSingleObject(Thread2,INFINITE);
::CloseHandle(Thread2);
cout<<"m="<<m<<endl;
cout<<"n="<<n<<endl;
system ("pause");
return 0;
}
Today i've met with a big problem. After compling the following
document, I entered 4 integers but cannot get what I want. how can I
modify it and get the result that I want? (input a,b,c,d and get m=a+b
+c+d , n=a*b*c*d).
Thanks in advance!
#include <windows.h>
#include <iostream.h>
#include <cstdlib>
int a,b,c,d;
int m,n;
DWORD WINAPI ThreadFunc1(HANDLE Thread1) //define thread1
{
m=a+b+c+d;
return 0;
}
DWORD WINAPI ThreadFunc2(HANDLE Thread2) //define thread2
{
n=a*b*c*d;
return 0;
}
int main() //main function
{
HANDLE Thread1;
HANDLE Thread2;
DWORD dwThreadId1;
DWORD dwThreadId2;
int a,b,c,d;
int m,n;
cout<<"please input a,b,c,d:"<<endl;
cin>>a>>b>>c>>d;
Thread1=::CreateThread //create thread1
(NULL,0,ThreadFunc1,NULL,0,&dwThreadId1);
Thread2=::CreateThread //create thread2 (NULL,
0,ThreadFunc2,NULL,0,&dwThreadId2);
::WaitForSingleObject(Thread1,INFINITE);
::CloseHandle(Thread1);
::WaitForSingleObject(Thread2,INFINITE);
::CloseHandle(Thread2);
cout<<"m="<<m<<endl;
cout<<"n="<<n<<endl;
system ("pause");
return 0;
}