2009-06-24

Thread and Tcl

package require Thread
catch {console show}

set ::gThread [thread::create {thread::wait} ]

proc printTime { } {
thread::send -async $::gThread { puts stdout [clock format [clock seconds]] }
after 1000 printTime
}

printTime
puts "started test..."

#only needed for tclsh, to keep the interpreter alive and keep the event loop running
vwait forever
在經過一段時間的學習以後,我才慢慢的看懂了 Tcl 的 Thread 擴充套件應該怎麼用才對,相關的資訊可以看 Tcl Threading Model

如果要檢查 tclsh 是不是 build 成支援 thread,則可以用
expr {[info exists ::tcl_platform(threaded)] && $::tcl_platform(threaded)}
來做到。當值為 1 時,表示有支援。

沒有留言: