Im currently developing the multithreading in Simulate.jl
. Now – with the current development version – I create a master clock and setup three parallel clocks:
using Simulate
clk = Clock()
multiply!(clk)
got 3 threads parallel to master!
I then create a test variable and an event with an anonymous function to increment it:
a = 1
ev = Simulate.SimEvent(SF(()->global a+=1),Main,1.0,0.0)
Simulate.SimEvent{SimFunction}(SimFunction(Main, var"#7#8"(), nothing, nothing), Main, 1.0, 0.0)
I can execute this and it does, what it should do. If I send this event over the event channel to the 1st parallel clock (on thread 2) and tell it to run, I get an exception telling me that it doesn’t know my newly created method var"#7#8"
:
put!(clk.ac[1].ch, Simulate.Register(ev)) # I register the event to the clock on thread 2
take!(clk.ac[1].ch) # I get the response
put!(clk.ac[1].ch, Simulate.Run(10.0)) # I tell the clock to run
Simulate.Run(10.0)
clock 2 exception: MethodError(var"#7#8"(), (), 0x000000000000689e)
If I query the task on thread 2, I get the following funny message:
clk.ac[1].ref[]
Task (failed) @0x000000010de02f50
MethodError: no method matching (::var"#7#8")()
The applicable method may be too new: running in world age 26782, while current world is 26783.
Closest candidates are:
#7() at In[3]:2 (method too new to be called from this world context.)
If I change the sequence, define first my method and then multiply to parallel threads, everything works fine:
clk = Clock();
a = 1
ev = Simulate.SimEvent(SF(()->global a+=1),Main,1.0,0.0)
multiply!(clk) # now I start everything on the other threads
put!(clk.ac[1].ch, Simulate.Register(ev))
take!(clk.ac[1].ch)
put!(clk.ac[1].ch, Simulate.Run(10.0))
take!(clk.ac[1].ch)
got 3 threads parallel to master!
Simulate.Response(10.0)
I query the task as before:
clk.ac[1].ref[]
Task (runnable) @0x000000013adc0fd0
Should the above failure happen? Is there a way to sync the “parallel worlds” on different threads to my world (on thread 1) in order to exchange newly created functions between threads?
Funny problem, isn’t it?