正文

多线程编程示例2006-08-04 23:58:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/vfdff/17261.html

分享到:

#include <stdio.h>#include <conio.h>#include <time.h>#include <stdlib.h>#include <windows.h>#define DELAY 3#define LEN_STD_STR 3char stdandardStr[LEN_STD_STR] = "123"; DWORD ChildMain(); int main(){   INT giThreadNumber = 1; DWORD dwThreadId; HANDLE hThread; DWORD dwCreationFlags = 0; time_t *t1 = NULL; time_t *t2 = NULL; int oldTime = 0, curTime = 0; oldTime = time(t1); hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ChildMain,                (LPVOID)giThreadNumber, dwCreationFlags, &dwThreadId);  for(;;){     curTime = time(t2);  if(curTime - oldTime >= DELAY){      printf("Time up!\n");   /* other function as follow */   printf("Other function!\n");   CloseHandle(hThread);  /*关掉不再使用的线程*/   return 0;  } }  system("pause"); return 0;} DWORD ChildMain(giThreadNumber){ int i = 0; char inputStr[LEN_STD_STR] = {0}; char ch; while(1){  ch = getche();  if(ch == 27){   printf("\nExit!\n");   goto Exit;   }else{   inputStr[i] = ch;  }  inputStr[3] = '\0';  if(strcmp(stdandardStr, inputStr) == 0){   printf("\nMatch!\n");   break;  }  i++;  if(i == 3){      i = 0;  } } /* other function as follow */Exit: printf("Other function!\n"); return 0 ;} 在 QQ845765 的 有人实现的!!! 可以在 CFREE 中或者 VC++ 下编译通过

阅读(622) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册