mypackage-init.tcl
if { ![nsv_exists . shutdown_pending] } { nsv_set . shutdown_pending 0 ns_atshutdown [list nsv_set . shutdown_pending 1] }
Then in your detached thread do something like:
while { ![nsv_get . shutdown_pending] } { ns_sleep 60 # Etc. }