编了一个简单的做试验都不行程序如下,只是用_beginthread创建一个线程并让它Sleep一会儿,在Console上输出一些东西,很简单的但结果却是什么都没有输出,为什么啊!?
#include <stdio.h>
#include <process.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>HANDLE hFinished;void ThreadProc(int *ID);void main(void){
int i=0;
hFinished=CreateMutex(NULL,TRUE,NULL);
_beginthread(ThreadProc,0,&i);
WaitForSingleObject(hFinished,INFINITE);
}void ThreadProc(int *ID){
printf("Thread %d starts",*ID);
srand(*ID);
Sleep(rand()*1000);
printf("Thread %d ends",*ID);
ReleaseMutex(hFinished);
}
#include <stdio.h>
#include <process.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>HANDLE hFinished;void ThreadProc(int *ID);void main(void){
int i=0;
hFinished=CreateMutex(NULL,TRUE,NULL);
_beginthread(ThreadProc,0,&i);
WaitForSingleObject(hFinished,INFINITE);
}void ThreadProc(int *ID){
printf("Thread %d starts",*ID);
srand(*ID);
Sleep(rand()*1000);
printf("Thread %d ends",*ID);
ReleaseMutex(hFinished);
}
解决方案 »
- 数据库的读写问题
- 求高人指教,opengl程序
- 有人知道skype怎样实现多语言的菜单项吗?
- ***********我有一个类CPerson,如何让它从CObject继承?在New Class对话框的下拉列表里没有CObject类啊*******
- 高分求教一个数据库问题,运行通过就结贴
- 机器没有1394接口如何进行远程调试?
- 菜鸟的问题:如何取得客户区中心点?以及坐标变换
- 如何把 char* 转换成CString??(char * 不是普通的char*,而是宽字符的)
- 同志们,伸出手,拉兄弟一把!!!!!
- 关于进程可以打开的文件句柄数?
- 就要过年了还问大家一个基础问题:temp =new char[1]
- AC_SRC_ALPHA的值是多少
时间太长了!
{
DWORD dwThreadId, dwThrdParam = 1;
HANDLE hThread; hThread = CreateThread(
NULL, // no security attributes
0, // use default stack size
ThreadProc, // thread function
&dwThrdParam, // argument to thread function
0, // use default creation flags
&dwThreadId); // returns the thread identifier int i=0;
WaitForSingleObject(hThread,INFINITE);
}DWORD WINAPI ThreadProc(void *p)
{
int *ID = (int*)p ;
printf("Thread %d starts",*ID);
srand(*ID);
Sleep( ( rand()%5 + 1 )*1000);
printf("Thread %d ends",*ID);
return 1 ;
}