@mashingan this confirms that even local value-typed variables are GC managed.. 
But using ref doesn't solve the problem: 
    
    
    type
        P2d = object
          x, y: float
        
        P2dp = proc(): ref P2d
    
    var thef: P2dp = nil
    
    proc foo(): auto =
        var pt : ref P2d
        new[P2d](pt)
        pt.x = 4
        pt.y = 5
        result = proc(): auto = pt
        pt.x = -1
    
    proc giveFoo() {.thread.} =
        thef = foo()
    
    var f = foo()
    echo f()[]
    
    var t: Thread[void]
    t.createThread giveFoo
    joinThread t
    if not thef.isNil:
        echo thef()[]
    else:
        echo "nothing"
    

this crashes in the same way as your version, which is not surprising since ref 
are GC managed but the GC is thread-local, so when the thread terminates pt is 
freed 

Reply via email to