Hi,
using channels is great, but to get data from another thread by starting the transaction from the primary thread, it is necessary to signal to the the secondary thread this. Example:
# primary module
import os
import secmodule
var
mythread: Thread[void]
counter = 0
createThread(mythread, secmodule.loop)
# More code ...
while true:
counter += 1
if counter == 10:
counter = 0
secmodule.send_flag = true
let data = secmodule.chan.recv()
echo data
sleep(1000)
# secondary module
import os
var
data = "some data"
chan*: Channel[string]
send_flag* = false
proc loop() =
while true:
if send_flag:
send_flag = false
chan.send(data)
sleep(10)
This works great, but is there a more direct way of getting the data variable across?
I'm not looking for speed, convenience is more important.
Thanks
Channels are the best at the moment.
In the future I think having a more convenient syntax:
is important