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

  1. # This could be minimally invasive implementation of env per interp/thread,
  2. # with "certain" backwards compatibility (at least on read)...
  3. # -------------------------------------------------------------------------
  4. # global_env - global env array (like in current tcl-implementation)
  5. # env - local interp/thread env, with automatical mirroring/merging
  6. # from global env (local wins on global) protected by epoch's
  7. # -------------------------------------------------------------------------
  8.  
  9. % puts "[thread::id -hex]: [array get env]"
  10. 2A84: a a-123 b b-234
  11. % puts "[thread::id -hex]: [array get global_env]"
  12. 2A84: a a-123 b b-234
  13.  
  14. % set env(c) [thread::id -hex]
  15. 2A84
  16. % set global_env(d) d-global
  17. d-global
  18. % puts "[thread::id -hex]: [array get env]"
  19. 2A84: d d-global a a-123 b b-234 c 2A84
  20. % puts "[thread::id -hex]: [array get global_env]"
  21. 2A84: d d-global a a-123 b b-234
  22.  
  23. % set t1 [thread::create]
  24.  
  25. % thread::send $t1 {return "[thread::id -hex]: [array get env]"}
  26. 251C: d d-global a a-123 b b-234
  27. % thread::send $t1 {set env(c) [thread::id -hex]}
  28. 251C
  29. % thread::send $t1 {return "[thread::id -hex]: [array get env]"}
  30. 251C: d d-global a a-123 b b-234 c 251C
  31.  
  32. % puts "[thread::id -hex]: [array get env]"
  33. 2A84: d d-global a a-123 b b-234 c 2A84
  34.  
  35. % set t2 [thread::create]
  36.  
  37. % thread::send $t2 {return "[thread::id -hex]: [array get env]"}
  38. 2230: d d-global a a-123 b b-234
  39.