最近学多线程,很多问题搞不明白,而且都很初级,希望各位不要笑话,
#define WIN32_LEAN_AND_MEAN
#include <stdio.h>
#include<stdlib.h>
#include<windows.h>
#include<conio.h>
DWORD WINAPI ThreadFunc1(LPVOID);
//DWORD WINAPI ThreadFunc2(LPVOID);
int main(){
HANDLE hThrt1;
HANDLE hThrt2;
DWORD threadID,exitCode1=0,exitCode2=0;
hThrt1=CreateThread(NULL,
0,
ThreadFunc1,
(LPVOID)1,
0,
&threadID);
if(hThrt1){
printf("threadfun1 has been begin\n");
}
hThrt2=CreateThread(NULL,
0,
ThreadFunc1,
(LPVOID)2,
0,
&threadID);
if(hThrt2){
printf("threadfun2 has been begin\n");
}
while(0){
printf("printf any key to exit\n");
getch();
GetExitCodeThread(hThrt1,&exitCode1);
GetExitCodeThread(hThrt2,&exitCode2);
if(exitCode1==STILL_ACTIVE){
puts("threadfun1 still active\n");
}
if(exitCode2==STILL_ACTIVE){
puts("threadfun2 still active\n");
}
if(exitCode1!=STILL_ACTIVE&&exitCode2!=STILL_ACTIVE){
// printf("all has been exit\n");
break;
}
CloseHandle(hThrt1);
CloseHandle(hThrt2);
}
return EXIT_SUCCESS;
}
DWORD WINAPI ThreadFun1(LPVOID n){
Sleep((DWORD)n*1000*2);
return (DWORD)n*10;
}
编译没有错误,可是一运行就这样:
--------------------Configuration: 实验8 - Win32 Debug--------------------
Linking...
实验8.obj : error LNK2001: unresolved external symbol "unsigned long __stdcall ThreadFunc1(void *)" (?ThreadFunc1@@YGKPAX@Z)
Debug/实验8.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
实验8.exe - 2 error(s), 0 warning(s)
为什么啊