如何在Haskell中杀死线程 [英] How to kill a thread in Haskell

查看:57
本文介绍了如何在Haskell中杀死线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Control.Concurrent和forkIO,在某些情况下会使线程处于阻塞状态(在联网的Windows中这种情况尤其常见),因此即使尝试使用killThread,也不会在线程中引发异常.

Using Control.Concurrent and forkIO, there are some cases that will leave the thread in a blocked state (this is especially frequent under Windows with networking) so even if one tries to use killThread the exception is never raised in the thread.

还有其他强制线程死亡的方法吗?

Is there any other way to force a thread to die?

在这种情况下,我试图通过helper线程使用exitFailure终止整个应用程序没有任何作用.

My attempt to terminate the whole application with exitFailure from a helper thread didn't have any effect under these conditions.

我使用的是Glorious Glasgow Haskell编译系统,版本6.12.1 惠普2010.1.0.0

I'm using the Glorious Glasgow Haskell Compilation System, version 6.12.1 HP 2010.1.0.0

为了清理起见,我不想终止应用程序,我宁愿只是杀死已经被阻塞很长时间的线程.

To clear things up, I don't want to terminate the application, I would prefer to just kill the thread that have been blocked for a very long time.

但是,即使在SO上也有很多示例,它们在辅助线程中使用exitWith编写了完整的代码,这种方案在我的条件下不起作用.

However, there are numerous examples even here on SO with complete code using exitWith in a helper thread and that kind of scheme doesn't work under the conditions I have.

推荐答案

在上面的评论中,您不能打断阻止外来电话.但是,您可以使用非阻塞IO.对于Network程序包,这意味着recvLen表示字符串,recvFrom表示字节字符串.我认为您也总是在指定线程运行时?

To expand on my comment above, you can't interrupt blocking foreign calls. You can, however, use nonblocking IO. In the case of the Network package, this means recvLen for strings, and recvFrom for bytestrings. I assume you're always specifying the threaded runtime as well?

这篇关于如何在Haskell中杀死线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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