|
2021-03-10
| ||
| 13:31 | • Closed ticket [d215ef73bb]: How to detect "unknown" command inside the... artifact: df9cd8015c user: sebres | |
| 06:00 | • Ticket [d215ef73bb]: 4 changes artifact: 63963dddd2 user: arvind29 | |
|
2021-03-09
| ||
| 09:32 | • New ticket [d215ef73bb]. artifact: 296dc64319 user: arvind29 | |
How to detect "unknown" command inside the thread script in proc unknown of init.tcl file
We have a "unknown" command in thread script. We have "proc unknown args" in init file. Can we detect in this proc "proc unknown args" that this "unknown" command is coming from thread script?
tcl script file:
package require Thread
thread::create {
unknown_command
}
exit
> Can we detect in this proc "proc unknown args" that this "unknown" command is coming from thread script?
Not really (in direct way). Tcl interpreter (as well as unknown or also other handlers) do not imply usage of any thread facilities, neither distinguish the threads (indirectly the interpreter knows only its own thread where it belongs to).
File init.tcl is loaded in every interpreter (regardless the thread) if it gets created (initialized).
But this is occured in main thread as first... thread::create {
# mark thread as a helper thread:
set ::helper_thread 1
...
unknown_command
}
So either you would save the ID of the main thread and compare it inside your unknown handler like this:
Or you would set some marker for this thread (like here variable
# somewhere in main thread (or even in init.tcl):
if {![tsv::exists threads main]} {
tsv::set threads main [thread::id]
}
...
# in unknown handler:
if {[tsv::get threads main] ne [thread::id]} {
puts "this is helper thread"
}
::helper_thread):
Just note that in this case file
# in unknown handler:
if {[info exists ::helper_thread] && $::helper_thread} {
puts "this is helper thread"
}
init.tcl is called before init-script of thread::create gets called, so setting of set ::helper_thread 1 may be too late, if unknown handler gets invoked during some initialization process (inside init.tcl invocation).