Posted to tcl by sebres at Mon Jan 07 16:48:46 GMT 2019view pretty

# This could be minimally invasive implementation of env per interp/thread,
# with "certain" backwards compatibility (at least on read)...
# -------------------------------------------------------------------------
# global_env - global env array (like in current tcl-implementation)
# env        - local interp/thread env, with automatical mirroring/merging
#              from global env (local wins on global) protected by epoch's
# -------------------------------------------------------------------------

% puts "[thread::id -hex]: [array get env]"
2A84: a a-123 b b-234
% puts "[thread::id -hex]: [array get global_env]"
2A84: a a-123 b b-234

% set env(c) [thread::id -hex]
2A84
% set global_env(d) d-global
d-global
% puts "[thread::id -hex]: [array get env]"
2A84: d d-global a a-123 b b-234 c 2A84
% puts "[thread::id -hex]: [array get global_env]"
2A84: d d-global a a-123 b b-234

% set t1 [thread::create]

% thread::send $t1 {return "[thread::id -hex]: [array get env]"}
251C: d d-global a a-123 b b-234
% thread::send $t1 {set env(c) [thread::id -hex]}
251C
% thread::send $t1 {return "[thread::id -hex]: [array get env]"}
251C: d d-global a a-123 b b-234 c 251C

% puts "[thread::id -hex]: [array get env]"
2A84: d d-global a a-123 b b-234 c 2A84

% set t2 [thread::create]

% thread::send $t2 {return "[thread::id -hex]: [array get env]"}
2230: d d-global a a-123 b b-234