I have a program on Windows that tries to distribute its work over multiple 
threads. They key function is this: 
    
    
    proc doJobs(config: Config) =
      var responses = newSeq[FlowVarBase]()
      for filename in getFilenames(config):
            responses.add(spawn doOneJob(config, filename))
      sync()
    

It never uses more than 1 CPU (i.e., the load is <=25% and there are 4 CPUs). I 
have the line threads:on in nim.cfg in the same directory as the .nim file.

Sometimes it crashes (see below, but the crashes vary).

But even if it worked, I can't see how to read the data from the responses 
(doOneJob returns a string). I tried this approach:
    
    
    proc doJobs(config: Config) =
      var responses = newSeq[FlowVarBase]()
      for filename in getFilenames(config):
        responses.add(spawn doOneJob(config, filename))
      sync()
      while responses.len() > 0:
        let i = awaitAny(responses)
        # HOW to retrieve the result string from responses[i] ???
        responses.delete(i)
    

But I don't know how to retrieve each result. (And it crashes just the same as 
the first version.)
    
    
    Problem signature:
      Problem Event Name:       APPCRASH
      Application Name: searchpdfscmd_mt.exe
      Application Version:      0.0.0.0
      Application Timestamp:    58cbf004
      Fault Module Name:        KERNELBASE.dll
      Fault Module Version:     6.1.7601.17514
      Fault Module Timestamp:   4ce7c78c
      Exception Code:   0eedfade
      Exception Offset: 000000000000a49d
      OS Version:       6.1.7601.2.1.0.768.3
      Locale ID:        2057
      Additional Information 1: 1eed
      Additional Information 2: 1eed067d6796a8e0420d9b30949e74df
      Additional Information 3: 1bea
      Additional Information 4: 1beaf66c25b9dc300af529f0c5670747
    
    Read our privacy statement online:
      http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409
    
    If the online privacy statement is not available, please read our privacy 
statement offline:
      C:\Windows\system32\en-US\erofflps.txt
    

Reply via email to