multithreading - Will Tcl Interp created in separate threads share any global data? -
in c++ code, if create 1 tcl interp per thread, , use tcl_evalex script, , result tcl_getstringresult, thread safe?
there's no shared data between these threads except const data.
after searching on google found in tcl threading model doc: http://www.tcl.tk/doc/howto/thread_model.html
tcl lets have 1 or more tcl interpreters (e.g., created tcl_createinterp()) in each operating system thread. however, each interpreter tightly bound os thread , errors occur if let more 1 thread call same interpreter (e.g., tcl_eval).
i guess means if don't shared data between interpreters, there should no issue?
i create 1 tcl interp per thread, , use
tcl_evalex
script, , resulttcl_getstringresult
, thread safe?
yes. tcl's engine uses thread-specific data extensively, transferring interpreter between threads impossible[*] (things break horribly), have up-side thread-safety guaranteed @ same time. main thing remember use tcl's built-in memory allocator functions when intermingling tcl's implementation @ instead of trying yourself, 1 of key things threaded tcl uses thread-aware memory allocator (much faster, given data stays bound single thread).
simple code can, indeed, stay simple. nice, yes?
[*] ok, it's possible if tricks building non-thread-aware version , on, it's tricky , 1 deep experts potential catastrophic problems high. tcl's highly partitioned model hugely easier work with.
Comments
Post a Comment