Haskell 获取线程名
我正在使用Haskell的async操作符,我想打印线程名称,但我在谷歌上搜索了一下,找不到方法 这是我的密码Haskell 获取线程名,haskell,Haskell,我正在使用Haskell的async操作符,我想打印线程名称,但我在谷歌上搜索了一下,找不到方法 这是我的密码 asyncResponse = do resAsync <- async operation response <- wait resAsync print response operation = do threadDelay 5000000
asyncResponse = do
resAsync <- async operation
response <- wait resAsync
print response
operation = do
threadDelay 5000000
return "hello async world!!" --> Here Thread name
asyncResponse=do
resAsync您可以使用myThreadId
获取ThreadId
,它作为线程的标识符,如下程序所示:
import Control.Concurrent
import Control.Concurrent.Async
main = asyncResponse
asyncResponse = do
resAsync <- async operation
response <- wait resAsync
print response
operation = do
threadDelay 5000000
myid <- myThreadId
return ("hello async world!! my name is " ++ show myid)
这或多或少是接近你会得到一个线程“名称”。这就是你想要的吗?你说的“线程名称”是什么意思?一个线程有一个线程ID
,但这不是一个确切的名称。Haskell没有异步操作符。您使用的是什么模块?import Control.Concurrent.Async和关于名称,在基于JVM的其他语言中,通常每个模块都有一个名称Thread@Michael_Litchard具体来说,@paul正在使用async
包。也许我是盲人,但我读了异步包docu,却找不到任何东西。顺便说一句,我的问题不好吗?。
"hello async world!! i am thread ThreadId 5"