I am trying to test memory fragmentation after thread destruction, but I don't 
know how to destroy threads properly. What is wrong with this program? 
    
    
    import os
    
    var threads: seq[Thread[int]]
    
    proc wait(s: int) =
      for i in 0..10:
        var x = newStringOfCap(100000*(11-i))
      os.sleep(s*1000)
    proc cycle() =
      for i in 0..threads.high:
        assert(not running(threads[i]))
        createThread(threads[i], wait, 1)
      echo "Joining", threads.len
      joinThreads(threads)
      echo "Joined", threads.len
    proc main() =
      newSeq(threads, 4)
      for i in 0..30:
        cycle()
    main()
    
    
    
    Joining4
    Joined4
    Joining4
    .... (hangs here)
    

Reply via email to