I am trying to run a thread continuously and not have it become blocked by the tcl main event loop. Here is a simple example of what I'm trying to do:
#!/bin/sh
#\
exec tclsh "$0" "$@"
package require Thread
set ::a_thread [thread::create {thread::wait}]
proc start_a {} {
thread::send $::a_thread {
puts "Running a thread"
}
after 1000 a_start
}
proc infinite_loop {} {
while {1} {
puts "Loop"
after 500
}
}
start_a
infinite_loop
vwait forever
In this code, the infinite_loop
proc is called and the main event loop runs infinitely. I would like it if the a_thread
could still run in the background though. How can I achieve this?