Hi all, Relatively new to nim, very new to multithreading in nim. I'm 
attempting to run a program on a bunch of files I have the file paths for. The 
relevant code at the moment is the following: 
    
    
    var t1 : seq[Thread[(string,string,string,uint16,uint16)]]
    for file in files:
      while true:
        if t1.len < int(thread_num):
          t1.add(Thread[(string,string,string,uint16,uint16)]())
          createThread(t1[t1.len - 1], myFunction, (file, ... <other stuff>))
          break
        else:
          var added_flag = false
          for i,thr in t1:
            if not t1[i].running:
              t1[i] = Thread[(string,string,string,uint16,uint16)]()
              createThread(t1[i], myFunction, (file, ... <other stuff>))
              added_flag = true
              break
          if added_flag:
            break
        os.sleep(1)
    joinThreads(t1)
    for thr in t1:
      assert not thr.running
    
    
    Run

I would expect all the threads in t1 to have finished running by the time I hit 
my assert statement, because I used joinThreads(), but that doesn't seem to be 
the case. Is my logic totally off? Am I misunderstanding how to properly use 
nim threads and joinThreads() in particular? Any help you could provide would 
be much appreciated. 

Reply via email to