I imagine the C++ operators are tied to the main TouchDesigner thread. Python threading is dangerous, can the same be said about threading inside of a C++ operator?
I wouldn’t say Python threads are dangerous. They need to follow the same rules as any threading environment which is protecting data that could be read/write by multiple threads at the same time to avoid race conditions. This is true for threads in all languages.
So in C++ it’s the same, data that TD owns is data that you can’t protect so you need to modify that in the main thread. All other data that you own you can modify however you want using threading protections available in your language.
The CPUMemoryTOP example has 3 data pointers that are intended to be filled by other threads infact.
Thanks, Malcolm, I’ll check out that example.
Would that extend to something like audio in a situation like making a C++ CHOP that doesn’t take any inputs but outputs audio? Would that audio being read in TouchDesigner and being generated in the C++ CHOP fall under data you’d want to be careful of?
All of the data in both ‘const CHOP_Output* output’ and ‘OP_Inputs* inputs’ is owned by TD and should only be modified inside of execute(). If you are trying parallalize work inside of execute(), for example filling many channels at once, each with it’s own thread, then yes you can do that as long as all the work is done before execute() returns.