阅读:1649回复:3
请教一下多线程的问题
请大家帮我看一下,为什么子线程只执行了一次?
#include<iostream.h> #include <windows.h> int i; DWORD WINAPI fun1proc(LPVOID lpParameter); int main() { HANDLE thread1; thread1 = CreateThread(NULL,0,fun1proc,NULL,0,NULL); CloseHandle(thread1); for(i=5;i>0;i--) { switch(i) { case 5: cout<<" 5 "<<endl; break; case 4: cout<<" 4 "<<endl; break; case 3: cout<<" 3 "<<endl; break; case 2: cout<<" 2 "<<endl; break; case 1: cout<<" 1 "<<endl; break; default: cout<<" 0 "<<endl; break; } Sleep(1000); } cout<<"ready go!!!!"<<endl; return 0; } DWORD WINAPI fun1proc(LPVOID lpParameter) { cout<<"there is "<<i-1<<" second left"<<endl; return 0; } |
|
|
沙发#
发布于:2007-04-04 15:12
就是显示了5,之后 跟着有4秒left
但是后面都只有主线程在执行了 |
|
|
板凳#
发布于:2007-04-04 15:14
谢谢大家了
|
|
|
地板#
发布于:2007-04-04 16:58
我自己想明白了,原来子线程已经执行完了,生命已经结束了,所以父线程接着一直往下执行...
|
|
|