I'm trying to define a "configurable proc", to be called by threads. Although I 
would assume procs cannot be garbage collected(?), I get told calling it is not 
GC-safe. I have tried defining the proc "value" as gcsafe through it's type, 
but that doesn't seem to work either.

I guess the "user" could just define the "now" proc directly as a normal proc, 
but I'm still wondering what I'm doing wrong here. Also, I might want to 
instead have now as a hidden global var, setup at runtime, before creating any 
thread. In that case, defining it as a "simple proc" in the "configuration 
module" would not work.
    
    
    # This part in "configuration module":
    type
      Timestamp* = float
      
      TimestampProvider* = proc (): Timestamp {.gcsafe.}
    
    import times
    let now*: TimestampProvider = cpuTime
    
    # This part in "implementation module":
    proc caller() {.thread.} =
      echo("NOW: " & $now())
    
    var thread: Thread[void]
    createThread[void](thread, caller)
    
    joinThread(thread)
    

Reply via email to