My English is not good. Still, I will try to explain what I had in my mind a
bit more before I give up.
I was answering these:
> Araq: How can you assume a lock on the "root" Node? The compiler has no idea
> about a "root" node
>
> PMunch: Indeed having a rule like "every local variable involved in isolate
> must not be used afterwards" would vastly improve the system
In short, my idea was confining graph creation into single proc. I guess its
still not an easy job at all if it is even possible but I thought it might make
the analysis easier somehow while providing a way to what OP and PMunch has
asked.
import std / [json, isolation]
import threading / channels
var chan = newChan[JsonNode]()
var thr: Thread[void]
proc worker() {.thread.} =
let x = chan.recv()
echo "Welcome ", x["user"], x["msg"], " from ", x["uri"]
# this should be magic in compiler
template isolate(b: untyped): untyped =
b
# this is not an ordinary procedure, its a graph generator
proc buildTree(uri, msg, user : string) : JsonNode {.isolate.} =
# I'm telling the compiler, this proc and only this proc is where I'll
create my graph.
# Consider the return value as my graph root. You may ignore refcount of
children
# but root should have atomic refcount. IDK if extra rules about proc
arguments is needed.
# also not sure how but children must be destroyed too when root is
destroyed
var root = newJObject()
root["uri"] = %uri
root["msg"] = %msg
root["user"] = %user
# real return value should be isolated JsonNode, dont let me break the
rules outside of this proc
return root
echo "Name?"
let user = stdin.readLine()
createThread thr, worker
# this would be an error:
# var x = buildTree("example.com","Hello",user)
# someProcess(x)
# but is it possible to make this work ?
let t = buildTree("example.com","Hello",user)
# chan.send t
# instead of this:
chan.send unsafeIsolate(t)
joinThread thr
Run