小编arc*_*erk的帖子

Nim 对多个线程进行计数

我目前正在尝试计算我请求网站的次数。在 python 中,我只会使用一个全局变量,但我不知道如何在 nim 中编写它。

import httpclient

proc threadMain(a: int) {.thread.} =

    var client = newHttpClient()
    while true:
      try:
        var r = client.getContent("URL")
        echo "sent"
        #Count here
      except:
        echo "error"

var thread: array[0..10, Thread[int]]

for i in 0..10:
  thread[i].createThread(threadMain, i)

thread.joinThreads()
Run Code Online (Sandbox Code Playgroud)

nim-lang

2
推荐指数
1
解决办法
1166
查看次数

标签 统计

nim-lang ×1