二. WaitForMultipleObject 等待单个线程返回

1. 函数原型
DWORD WINAPI WaitForMultipleObjects(
_In_ DWORD nCount,
_In_ const HANDLE *lpHandles,
_In_ BOOL bWaitAll,
_In_ DWORD dwMilliseconds
);
2. 参数说明
  • 第一个参数 nCount 为等待的内核对象个数,可以是 0 到 MAXIMUM_WAIT_OBJECTS (64)中的一个值。
  • 第二个参数 lpHandles 为一个存放被等待的内核对象句柄的数组。
  • 第三个参数 bWaitAll 是否等到所有内核对象为已通知状态后才返回,如果为 TRUE,则只有当等待的所有内核对象为已通知状态时函数才返回,如果为 FALSE,则只要一个内核对象为已通知状态,则该函数返回。
  • 第四个参数 dwMilliseconds 为等待时间,和 WaitForSingleObject 中等待 dwMilliseconds 参数类似。
3. 返回值
  • WAIT_ABANDONED_0 表示所有对象都发出消息,而且其中有一个或对个属于互斥体(一旦拥有他们的进程结束,就会发出信号)
  • WAIT_TIMEOUT 对象保持未发出信号的状态,但规定的等待超时时间已经超过
  • WAIT_OBJECT_0 所有对象都发出信号
  • WAIT_FAILED 表示函数执行失败,会设置错误码,错误码可通过 GetLastError 获取
  • WAIT_IO_COMPLETION (仅适用于 WaitForMultipleObjectsEx )由于一个 I/O 完成操作已做好准备执行,所以造成了函数的返回值

    —— 如果 bWaitAll 为 FALSE,那么返回结果相似,只是可能还会返回相对于 WAIT_ABANDONED_0 或 WAIT_OBJECT_0 的一个正偏移量,指出哪个对象时被抛弃还是发出信号。

    补充: WAIT_OBJECT_0 时微软定义的一个宏,就可以把这个宏当做一个数字。

例如, 返回值 WAIT_OBJECT_0 + 5 意味着列表中的第 5 个对象发出了信号。当 bWaitAll 参数为 FALSE 时可以等待其中之一的信号。

4. 示例

(1)参数 bWaitAll 为 FALSE,只要一个内核对象为已通知状态,则该函数返回。

#include <Windows.h>
#include <stdio.h> const unsigned int THREAD_NUM = 3;
DWORD WINAPI ThreadFunc(LPVOID p)
{
printf("I am a child thread 0 which pid is %d ...\n", GetCurrentThreadId()); //输出子线程pid
Sleep(500);
printf("The child thread 0 which pid is %d quit ...\n", GetCurrentThreadId());
return 0;
} DWORD WINAPI ThreadFunc1(LPVOID p)
{
printf("I am a child thread 1 which pid is %d ...\n", GetCurrentThreadId()); //输出子线程pid
Sleep(2000);
printf("The child thread 1 which pid is %d quit ...\n", GetCurrentThreadId());
return 0;
} DWORD WINAPI ThreadFunc2(LPVOID p)
{
printf("I am a child thread 2 which pid is %d ...\n", GetCurrentThreadId()); //输出子线程pid
Sleep(4000);
printf("The child thread 2 which pid is %d quit ...\n", GetCurrentThreadId());
return 0;
} int main()
{
printf("I am the main thread that pid is %d ...\n", GetCurrentThreadId()); //输出主线程pid
HANDLE hThread[THREAD_NUM];
hThread[0] = CreateThread(NULL, 0, ThreadFunc, 0, 0, NULL); // 创建线程
hThread[1] = CreateThread(NULL, 0, ThreadFunc1, 0, 0, NULL); // 创建线程
hThread[2] = CreateThread(NULL, 0, ThreadFunc2, 0, 0, NULL); // 创建线程 DWORD resulut = WaitForMultipleObjects(THREAD_NUM, hThread, FALSE, INFINITE); //只要有一个线程返回就结束
if (WAIT_OBJECT_0 == resulut)
{
printf("The child thread 0 finished waiting ...\n");
}
else if (WAIT_OBJECT_0 + 1 == resulut)
{
printf("The child thread 1 finished waiting ...\n");
}
else if (WAIT_OBJECT_0 + 2 == resulut)
{
printf("The child thread 2 finished waiting ...\n");
}
else if (WAIT_FAILED == resulut)
{
printf("The fuction WaitForMultipleObjects error! \n");
}
printf("The main thread which pid is %d quit ...\n", GetCurrentThreadId());
return 0;
}

输出结果为:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZYAAACuCAYAAAAVpiviAAAf40lEQVR4nO2dz28cyXXHq4ezkqONYpJZGzaMRUSOg5wCRFLoUw4CGCHIyYEj3gMZYPwDNuQ/IIdcc7EQI3DAkxHEsL2U117nYMAEASWAg8gKKdtwgiTAiFIMYx1jl0PtrrVarcRJV083WVOsH69+9Y/h94NdaNhd9erVq+p6Va9qprPRaDTe2tpiAIDmG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zZ6z/6yfnGMte1CYyzYhNg7E843YNi9kGVxuuM3nVakQX5lKloegnOyrVfdPqj2IjAABokhd/4xzr/8+DX7KFc+YvSJociPy3bl/ARuxB0nfFoloZmNLIMnUrPnmVoXKsKt3EtHAkAIC20z9zhvXfnzvDHr//ljGhz56FnL/uQTH23oNtn8QUmtKFx+S9FF1+hL0AAF3h6ZN3Wf/c+XOMPQlfsdjyyyualIOkS3jKJke3OtE5AJs+pus2O+s+w+EAANrCm2/us36/95y9/+y9EzflkFAopjBSLFRhJteVBOUeRY+q7JD8KhmmjftY5TaVHwDQfT44v8D6H//477L/2zuYukHdSHfFNCjWibhnYVqR6PS12cOnbpT8VIcJAABN0eu/wPpnXzjHzr/4W1M3fPdLqPeog6LKeak2t21luw6+ulWPKb1tZWT625a/yqMKncl6htB0fgBA93n3yVOW/dVXfjh+MvpP9tW/+ZIykcseg+qeKTziE6KiYltRdWUQtIWXsGoBAMQixou+vv2P32bZ174/HA9/9i/sy3+NN0gCAMBpJoZj+cbXvsV6Zz/QZ+PxOJJaAAAATjNPnz5lvdd/PmIfPP+bTesCAABgBnjpwx9ivRfPvcB+9as3m9YFAADADHAwGrHexz58jv32/LmmdQEAADAD8Hfe95699zY7M9e0KgAAAGaBD5w9y3qj13/JnrzzuGldAAAAzABnz5xhvd/5yEts4bz+Z/MBAAAAKgejA9Z7Z/91tv/G603rAgAAoIXcuHHD6fpbjx6x3ptv/IKx509T6gUAAKDDyE5E51Q4L7/8Mut94g9+n738sY+k1gsAAECHqZyJyalw+mfmWO/8hz7KPvAi9lgAAACc5ObNm0efRaciXhfJ5nqsl52dY+yFfnLlAAAAdBPZieicCufx48es9/pBxt45+Z4vAAAA4IjKmZicCmdubo71/vfgORs9xo9QAgAAMGNzKpysl7H/BzuYvLtyH6BiAAAAAElFTkSuQmCC" alt="image">

—— 如果将代码中的 “Thread 0” 的 Sleep 时间加长,让 “Thread 1” 先退出,则 会进入 WAIT_OBJECT_0 + 1 == resulut 分支,打印 “The child thread 1 finished waiting ...”,然后退出主线程。这样就可以通过返回值判断是哪个对象发送的信号。

(2)参数 bWaitAll 为 TRUE,等待所有线程返回。

#include <Windows.h>
#include <stdio.h> const unsigned int THREAD_NUM = 3;
DWORD WINAPI ThreadFunc(LPVOID p)
{
printf("I am a child thread 0 which pid is %d ...\n", GetCurrentThreadId()); //输出子线程pid
Sleep(500);
printf("The child thread 0 which pid is %d quit ...\n", GetCurrentThreadId());
return 0;
} DWORD WINAPI ThreadFunc1(LPVOID p)
{
printf("I am a child thread 1 which pid is %d ...\n", GetCurrentThreadId()); //输出子线程pid
Sleep(2000);
printf("The child thread 1 which pid is %d quit ...\n", GetCurrentThreadId());
return 0;
} DWORD WINAPI ThreadFunc2(LPVOID p)
{
printf("I am a child thread 2 which pid is %d ...\n", GetCurrentThreadId()); //输出子线程pid
Sleep(4000);
printf("The child thread 2 which pid is %d quit ...\n", GetCurrentThreadId());
return 0;
} int main()
{
printf("I am the main thread that pid is %d ...\n", GetCurrentThreadId()); //输出主线程pid
HANDLE hThread[THREAD_NUM];
//创建第一个子线程
hThread[0] = CreateThread(NULL, 0, ThreadFunc, 0, 0, NULL); // 创建线程
hThread[1] = CreateThread(NULL, 0, ThreadFunc1, 0, 0, NULL); // 创建线程
hThread[2] = CreateThread(NULL, 0, ThreadFunc2, 0, 0, NULL); // 创建线程 int wait_num = 0;
while (wait_num < THREAD_NUM)
{
DWORD resulut = WaitForMultipleObjects(THREAD_NUM, hThread, TRUE, INFINITE); //所有子线程返回才结束
if (WAIT_OBJECT_0 <= resulut <= WAIT_OBJECT_0 + 2)
{
printf("The Return value is %d, One child thread finished waiting ...\n", resulut);
wait_num++;
}
} printf("The main thread which pid is %d quit ...\n", GetCurrentThreadId());
return 0;
}

输出结果为:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgsAAADnCAYAAACQRhUeAAAgAElEQVR4nO2dX4xdx33f55w9S9Kx6ESVW0WW4T8VKdmUkgfbKBDKQPSQNiDlogSKKg9F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nTUhIQ6AOhLWzqg2rwTrvA+D4bruy9+F4fatjD1jGHo+AAAAMqk+me/9e+mv/fds+rbX/4MGUCyZ0/dc7mmQ7YHuPg8H2MZ2Hyu/VXxLmAbAgAA8nH//n117969pWtXrlxR29vbx8JS16svf+WN6X/6Xx+2ThYAAAAAMG5sk4UWfWJAXWupf3jP8cMQAAAAAFhpuglC9z9FXamNvvQBAAAAQCFQHgXzekd94uTxA44AAAAAWH3MiQE1UWip793zv+4ZAAAAAKtJN0GwTRRa6r1J1Zc+AAAAACgQ10ShpX7k9GM9qQIAAACAMVJPpo8MrQMAAAAACub/A1BIyBr9LtYbAAAAAElFTkSuQmCC" alt="image">

03等待多个线程返回WaitForMultipleObject的更多相关文章

  1. windows多线程(二) 等待线程返回

    多线程编程中,有时我们需要等待某一线程完成了特定的操作后再继续做其他事情,要实现这个目的,可以使用Windows API函数WaitForSingleObject,或者WaitForMultipleO ...

  2. Linux 进程与线程二(等待--分离--取消线程)

    int pthread_join(pthread_t thr,void **thr_return); pthread_join函数用于挂起当前线程,直至th指定的线程终止为止. 如果另一个线程返回值不 ...

  3. 02等待单个线程返回WaitForSingleObject

    windows 多线程之等待线程返回 ​ 多线程编程中,有时我们需要等待某一线程完成了特定的操作之后再继续做其他事情,要实现这个目的,可以使用 Windows API 函数 WaitForSingle ...

  4. 分析案例:应用服务无响应,任务管理器中发现大量w3wp僵尸进程----等待异构系统WebService返回值

    问题描述:       某二次开发的项目反馈,不定期出现应用服务器无响应的情况,登录服务器发现任务管理器中有大量的w3wp僵尸进程. 分析过程: 针对同一进程每隔15秒抓取dump,连续抓取3个,对比 ...

  5. c#等待所有子线程执行完毕方法

    当我们在使用线程中,你会发现主线结束后子线程的结果才显示出来.现在我要等待所以子线程结束,然后在显示结果,怎么做呢? 方法如下: 1.使用 ManualResetEvent,代码如下:  using  ...

  6. 深入Callable及Runnable两个接口 获取线程返回结果

    今天碰到一个需要获取线程返回结果的业务场景,所以了解到了Callable接口. 先来看下下面这个例子: public class ThreadTest { public static void mai ...

  7. Win32线程——等待另一个线程结束

    转载: https://blog.csdn.net/yss28/article/details/53646627 <Win32多线程程序设计>–Jim Beveridge & Ro ...

  8. Android平台调用Web Service:线程返回值

    接上文 前文中的遗留问题 对于Java多线程的理解,我曾经只局限于实现Runnable接口或者继承Thread类.然后重写run()方法.最后start()调用就算完事,可是一旦涉及死锁以及对共享资源 ...

  9. java主线程等待所有子线程执行完毕在执行(常见面试题)

    java主线程等待所有子线程执行完毕在执行(常见面试题) java主线程等待所有子线程执行完毕在执行,这个需求其实我们在工作中经常会用到,比如用户下单一个产品,后台会做一系列的处理,为了提高效率,每个 ...

随机推荐

  1. 洛谷P2939 [USACO09FEB]改造路Revamping Trails

    题意翻译 约翰一共有\(N\))个牧场.由\(M\)条布满尘埃的小径连接.小径可 以双向通行.每天早上约翰从牧场\(1\)出发到牧场\(N\)去给奶牛检查身体. 通过每条小径都需要消耗一定的时间.约翰 ...

  2. Kestrel服务器启动并处理Http请求

    从Hosting开始   知识点: 1.Kestrel服务器启动并处理Http请求的过程. 2.Startup的作用. 源码飘香: 总结: asp.net core将web开发拆分为多个独立的组件,大 ...

  3. selenum autoit上传图片

    目前,一般实现文件图片上传的方式都是有一个按钮,点击之后直接调用操作系统自身的弹框,选择文件后,实现上传.因为Selenium不支持调用操作系统的操作,所以这种情况下,利用Selenium无法完成图片 ...

  4. 把本地项目上传到github 不使用eclipse

    https://blog.csdn.net/m0_37725003/article/details/80904824

  5. Java常用函数式接口--Consumer接口andThen()方法使用案例(二)

    Java常用函数式接口--Consumer接口使用案例

  6. hard link && symbolic link

    hard link :硬连接,多了一个inode,指向原始的inode,通过这个硬连接删除文件,文件不会被真正删除,而是删除这个inode symolic link:符号连接相当于快捷方式

  7. zuul的本地跳转

  8. 使用 Kendo UI 库实现对象的继承

    使用 Kendo UI 库实现对象的继承 javaScript 也是一种面向对象的开发语言,但和 C++,Java,C# 所不同的是,它的对象不是基于类(Class),而是基于对象原型(ProtoTy ...

  9. C++ string 类型提取字符串

    在某些情况下需要对输入的字符串进行处理,提取其中的需要的信息. 比如在linux中输入"mkdir test",新建test文件夹,就需要提取其中的test字符. 提取的方法需要b ...

  10. <转>Java 高并发综合

    并发模型 悲观锁和乐观锁的理解及如何实现,有哪些实现方式? 悲观锁 悲观锁假设最坏的情况(如果你不锁门,那么捣蛋鬼就会闯入并搞得一团糟),并且只有在确保其他线程不会干扰(通过获取正确的锁)的情况下才能 ...