加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows – 一个线程可以调用SuspendThread传递自己的线程ID吗?

发布时间:2020-12-13 22:40:05 所属栏目:Windows 来源:网络整理
导读:Windows线程可以使用SuspendThread()挂起自己吗? 我可以从另一个唤醒它,但它可以调用SuspendThread(GetCurrentThreadId())吗? 解决方法 这似乎是可能的,但稍有改动(参见cygwin邮件列表讨论这个 here): SuspendThread(GetCurrentThread()); 我还发现MSDN说
Windows线程可以使用SuspendThread()挂起自己吗?

我可以从另一个唤醒它,但它可以调用SuspendThread(GetCurrentThreadId())吗?

解决方法

这似乎是可能的,但稍有改动(参见cygwin邮件列表讨论这个 here):

SuspendThread(GetCurrentThread());

我还发现MSDN说线程应该只是暂停,但它并没有让我清楚.我引用(从here开始,强调我的):

This function is primarily designed for use by debuggers. It is not intended to be used for thread synchronization. Calling SuspendThread on a thread that owns a synchronization object,such as a mutex or critical section,can lead to a deadlock if the calling thread tries to obtain a synchronization object owned by a suspended thread. To avoid this situation,a thread within an application that is not a debugger should signal the other thread to suspend itself. The target thread must be designed to watch for this signal and respond appropriately.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读