@woggioni, how about adding threading to your example, like
# compile with --threads:on --threadAnalysis:off
# because this thread need to modify `thef` value
type
P2d = object
x, y: float
P2dp = proc(): P2d
var thef: P2dp = nil
proc foo(): auto =
var pt = P2d(x: 4, y: 5)
result = proc(): P2d = 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"
As we can see, `thef` is not `nil` but the `P2d` defined from other thread is.
(I just followed the example, but we actually need ref object instead of object
)