Overview
| Artifact ID: | df9cd8015c5ca063888d3a5d7bf3301a7a5b9dec110260da40708f809b89419c |
|---|---|
| Ticket: | d215ef73bb9930338f44b8e3fa28e188c7597c21
How to detect "unknown" command inside the thread script in proc unknown of init.tcl file |
| User & Date: | sebres on 2021-03-10 13:31:21 |
Changes
- 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"