Multithreaded applications
Even though Tcl is designed to work efficiently in a single-threaded environment, it is possible to create separate threads in Tcl. While it can be used for performing any action, it is usually used for operations that take a lot of time to complete.
Threads in Tcl require that Tcl is built with threading enabled and has the package Thread
installed, which is true for all ActiveTcl installations. Tcl builds from various operating system distributions may or may not be built with thread support enabled—in this case, the Thread
package may not be present.
Managing threads
Tcl uses that approach that each thread is a separate entity and data is not normally shared across threads. It is possible to send commands to be evaluated in a thread, either waiting for them to finish or by having them performed asynchronously. In order to create a thread, we need to first load the Thread
package and use the thread::create
command:
package require Thread set tid [thread::create...