Neatware Header
Home   Products   Forums   Partners   Buy   Company   Contact   Blog   

16. Thread

The use of thread can increase the performance in the Pentium4 hyperthreading (HP) enabled PC and multiple processors (MP) system. So mCL allows developers to create multiple thread objects to speed up the computing of the motion of objects. Another instant application is to create interactive GUI control with thread.

This is the framework to use thread in mCL. thread::create launches a thread with identify tid and code specified in the inline ThreadCode function. The thread::wait command in the thread code allows thread to be scheduled.

inline ThreadCode {
  package require mcl

  proc threadFunc {args} {
    tsv::set ary $id $value
    ...
  }
  ...
  thread::wait
}

tsv::set ary ... command sets a value to shared array ary element id in thread. And tsv::get ary ... command returns the value stored in the shared array ary element id in main. The array variable is set to synchronized access.

proc main {} {
  set tid [thread::create [ThreadCode]]
  ...
  set var [tsv::get ary $id]
}