gpt4 book ai didi

c++ - 在 ACE 中优雅地终止线程

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:01:32 25 4
gpt4 key购买 nike

我有一个类似于 This one 的问题.但我想在 Linux 中使用 ACE 框架实现它。有什么方法可以做到这一点

最佳答案

多一点信息有助于获得更好的答案:

  • 您的工作线程在运行之前是否正在等待其他事件?
  • 您的线程如何相互通信?
  • 您是否始终能够正常终止,或者您是否预计必须强制终止某些线程?

other question你提到了一个很好的观点:

Typically, the way that a thread terminates is simply to return from the function that defines the thread. Generally, the main thread signals the worker thread to exit using an event object or a simply an integer or boolean value. If the worker thread is waiting in a WaitForSingleObject, you may need to change it to a WaitForMultipleObjects, where one of the objects is an event. The main thread would call SetEvent and the worker thread would wake up and return.

根据您在 ACE 中的设置,您可以使用从主线程到工作线程的进程间通信来告诉它们停止,它们将在下一次事件检查时获取并处理。或者,您可以使用 linux 的 select .

希望这能为您指明正确的方向。

关于c++ - 在 ACE 中优雅地终止线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2751096/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com