Artifacts Associated With Ticket d215ef73bb993033
Ticket change [296dc64319] (rid 192317) by arvind29 on 2021-03-09 09:32:52:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
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 - foundin initialized to: "8.6.8"
- is_private initialized to: "0"
- login: "arvind29"
- priority initialized to: "5 Medium"
- private_contact initialized to: "f31bbee5d57cdca64b0ff5fb39afeb99e5f9c194"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "arvind29"
- subsystem initialized to: "49. Threading"
- title initialized to:
How to detect "unknown" command inside the thread script in proc unknown of init.tcl file
- type initialized to: "Support"
Ticket change [63963dddd2] (rid 192351) by arvind29 on 2021-03-10 06:00:09:
- login: "arvind29"
- mimetype: "text/plain"
- priority changed to: "7 High"
- subsystem changed to: "80. Thread Package"
Ticket change [df9cd8015c] (rid 192384) by sebres on 2021-03-10 13:31:21:
- closedate changed to: "2459284.06344745"
- closer changed to: "sebres"
- icomment:
<blockquote><i>> Can we detect in this proc "proc unknown args" that this "unknown" command is coming from thread script?</i></blockquote> 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).<br/> File <code>init.tcl</code> is loaded in every interpreter (regardless the thread) if it gets created (initialized). But this is occured in main thread as first... <br/> So either you would save the ID of the main thread and compare it inside your unknown handler like this: <code><pre style="padding-left:10pt"> # 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" } </pre></code> Or you would set some marker for this thread (like here variable <code>::helper_thread</code>): <code><pre style="padding-left:10pt"> # in unknown handler: if {[info exists ::helper_thread] && $::helper_thread} { puts "this is helper thread" } thread::create { # mark thread as a helper thread: set ::helper_thread 1 ... unknown_command } </pre></code> Just note that in this case file <code>init.tcl</code> is called before init-script of <code>thread::create</code> gets called, so setting of <code>set ::helper_thread 1</code> may be too late, if unknown handler gets invoked during some initialization process (inside <code>init.tcl</code> invocation). - login: "sebres"
- mimetype: "text/x-fossil-wiki"
- status changed to: "Closed"