我用api CreateThread();
可是在我的线程函数中 DWORD Thread1()
没有执行
不知道为什么
还请各位解答,如能付上一个小程序的代码,那就感激不尽了
可是在我的线程函数中 DWORD Thread1()
没有执行
不知道为什么
还请各位解答,如能付上一个小程序的代码,那就感激不尽了
解决方案 »
- 不明白为什么
- Visual Studio.Net2005如何添加继承自CRecordset类的类
- 基于MFC框架编写的SPY++的源代码思想是什么?
- VC如何使用ADO向数据库中插入和读取图片,图片格式包括BMP、JPEG、GIF等格式
- 请问如何保存深度缓存 如何让累积缓存只记录当前的图片 而不改变图像的颜色
- 在Windows 2000下编译通过的程序,为什么在XP下无法运行?
- 如何用程序迅速判断本机是否安装了ipx协议!在线!
- 文件操作遇到的问题 求教
- Only you... can help me to resolve this very difficult problem!!
- 如何获得桌面上所有的窗口句柄?
- 新手问:关于消息机制的入门级问题
- 有谁知道intToHex这个函数在哪个头文件里?
* Numbers.c
*
* sample code for "Multithreading Applications in Win32"
* This is from Chapter 2,Listing 2_1
*
* Starts five threads and gives visible feedback
* of these threads running by printing a number
* passed in from the primary thread.
*
*/#define WIN32_LEAN_AND_MEAN
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>DWORD WINAPI ThreadFunc(LPVOID);int main()
{
HANDLE hThrd;
DWORD threadId;
int i; for (i=0;i<5;i++)
{
hThrd = CreateThread(NULL,
0,
ThreadFunc,
(LPVOID)i,
0,
&threadId );
if (hThrd)
{
printf("Thread launched %d\n",i);
}
} // Wiat for the threads to complete.
// We'll see a better way of doing this later.
sleep(2000); return EXIT_SUCCESS;
}DWORD WINAPI ThreadFunc(LPVOID n)
{
int i;
for (i=0;i<10;i++)
printf("%d%d%d%d%d%d%d%d\n",n,n,n,n,n,n,n,n);
return 0;
}
{
HANDLE hThrd;
DWORD threadId;
hThrd = CreateThread(NULL, 0,
(LPTHREAD_START_ROUTINE)ThreadFunc,
(LPVOID)i,
0,
&threadId );
if (hThrd)
{
printf("Thread launched %d\n",i);
}
} // Wiat for the threads to complete.
WaitForSingleObjeect(hThrd,INFINITE); //等待线程结束。 return EXIT_SUCCESS;
}DWORD WINAPI ThreadFunc(LPVOID n)
{
int i;
for (i=0;i<10;i++)
printf("%d%d%d%d%d%d%d%d\n",n,n,n,n,n,n,n,n);
return 0;
}