Tk is not completely thread-safe, but that's true of many GUI toolkits. Thread safety is difficult and time-comsuming to implement, and slows down code running on single-CPU systems, so many GUI toolkits don't bother with thread-safety.
However, you can easily adapt the standard solution to this limitation: only one thread owns the GUI. All GUI code should be executed by only one thread in your applicaton. If other threads want to update the GUI, they do so by passing messages to the GUI manager thread.
Of course, this is very similar to Tcl's overall threading model. Only one thread can control a Tcl interpreter. If another thread wants to interact with the interpreter, it must send a message to the interpreter, which is added to the interpreter's event queue. Of course, a thread can own multiple interpreters, and multiple threads can have their own interpreters, so you can get quite complex if you like. But when you start to mix in Tk code, only one of those interpreters should be managing your GUI. - Ken Jones, President
Avia Training and Consulting
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.