在Windows中加入等效项 [英] join equivalent in Windows

查看:148
本文介绍了在Windows中加入等效项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何等待线程在Windows中死亡?这是我想让我的代码看起来像:

How do I wait for a thread to die in Windows? This is what I want my code to look like:

main thread:

creating thread: thread1
waiting for thread1 to die
//rest of the code

使用Win32 API。

I am using Win32 API.

推荐答案

很容易:WaitForSingleObject可以阻塞当前线程给予其他线程的句柄。
$ b

It's easy: the WaitForSingleObject can block current thread given the other thread's handle.

void Thread1Proc()
{
   HANDLE hThread2 = CreateThread(...);
   WaitForSingleObject(hThread2, INFINITE);

   // by now thread #2 is over

}

这篇关于在Windows中加入等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆