Nim Compiler Version 0.17.3 (2017-10-25) [Linux: amd64]

Copyright (c) 2006-2017 by Andreas Rumpf

git hash: fa02ffaeba219ca3f259667d5161d30e47bb13e0

active boot switches: -d:release

* * *

Code:
    
    
    import os except sleep
    import posix, strutils
    import threadpool
    
    when isMainModule:
      proc main() =
        var i = 0
        while true:
          i.inc()
          echo i
          discard sleep(1)
      if fork() == 0:
        echo("Hello from the child!")
        spawn main()
        threadpool.sync()
      else:
        quit(QUITSUCCESS)
    

* * *

I was using 
[https://github.com/OpenSystemsLab/daemonize.nim](https://github.com/OpenSystemsLab/daemonize.nim)
 to try and write a simple daemon.

I ran into a problem where invoking threadpool's spawn from a forked process 
resulted in a deadlock.

The code above is a simplified example from how I am using daemonize.nim.

* * *

strace: Process 146711 attached

futex(0x65dd24, FUTEX_WAIT_PRIVATE, 1, NULL)

* * *

Is there any way around this? I couldn't find anything explicitly prohibiting 
threadpool from being used like this.

Reply via email to