But they just don't work along with each other.
import malebolgia
# import taskpools
import zero_functional
type
Boss* = ref object of RootObj
name*: string
Task* = ref object
fromBoss*: string
proc generateTasks*(boss: Boss): seq[Task] =
return @["dummy_string"] -->>
map(Task(
fromBoss: boss.name,
))
proc working(ds: ptr Boss) =
discard ds[].generateTasks()
proc main() =
let boss = Boss()
# crashes with malebolgia
var tasks: seq[Task]
var m = createMaster()
m.awaitAll:
m.spawn working(addr boss)
# Taskpool works fine
# var pool = Taskpool.new(5)
# pool.spawn working(addr boss)
# pool.syncAll()
# pool.shutdown()
main()
The error:
Building test/test using c backend
Info: compiling nim package using /root/.local/share/grabnim/current/bin/nim
Nim Output # test.nim:15
... # @["dummy_string"].zfun:
... # map(Task(fromBoss: boss.name))
... (proc (): auto =
... {.push, hint[XDeclaredButNotUsed]: off.}
... proc iterType(): auto =
... for it0 in @["dummystring"]:
... let it1 = when compiles(Task(fromBoss: boss.name)(it0)):
... Task(fromBoss: boss.name)(it0)
... else:
... Task(fromBoss: boss.name)
... result = (it0, it1)
... {.pop.}
... var res: seq[type(iterType()[1])]
... result = zfInit(res)
... for it0 in @["dummystring"]:
... let it1 = when compiles(Task(fromBoss: boss.name)(it0)):
... Task(fromBoss: boss.name)(it0)
... else:
... Task(fromBoss: boss.name)
... zfAddItemChk(result, -1, it1, "seq[string]", "", false))()
Traceback (most recent call last)
/run/media/root/e/nim/4/src/test.nim(41) test
/run/media/root/e/nim/4/src/test.nim(12) main
/root/.local/share/grabnim/nim-devel/lib/system/orc.nim(527) nimDecRefIsLastCyclicDyn
/root/.local/share/grabnim/nim-devel/lib/system/orc.nim(509) rememberCycle
/root/.local/share/grabnim/nim-devel/lib/system/orc.nim(156) unregisterCycle
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
The above code is generated by the debugging operator -->> from `zero_functional, I think it will be simplified to:
@[Task(fromBoss: boss.name)] So I don't see any problem here.
Any idea what causes the problem? I know how to work around it, but how to fix it (or them)?
Nim version: 2.3.1 devel OS: Linux
zero_functional is removed, its macro can be simplified to this:
import malebolgia
type
Boss* = ref object of RootObj
name*: string
Task* = ref object
fromBoss*: string
proc generateTasks*(boss: Boss): Task =
return (proc (): Task =
result = Task(fromBoss: boss.name)
)()
proc working(ds: ptr Boss) =
discard ds[].generateTasks()
proc main() =
let boss = Boss()
var tasks: Task
var m = createMaster()
m.awaitAll:
m.spawn working(addr boss)
main()
It seems to be caused by the closure return (proc (): .... It can't be simplified further, it doesn't crash if anything else is removed.
Yes, createThread also crashes:
proc main() =
let boss = Boss()
var t: Thread[ptr Boss]
createThread(t, working, addr boss)
joinThread(t) Well now you can report it on github as the test has no dependencies! :-)
It's either an ORC bug or a subtle mistake on your part, I don't know yet.