When developing a csound opcode using c++ framework it seems that std::thread isn’t that welcome . Why is that?
Are there any other limitations that one should have in mind? E.g. regarding memory management (smart pointers, containers…) or something else like only c++11 should be used and so on…
std::thread should work Ok. I’m not sure about containers, I don’t think I’ve ever used a smart pointer in any of my cpof opcodes. Note there is a deinit() function that you can register that will be called when the opcode is finished. You can tidy memory there if you need to.
opcode doesn’t run in csound (I get: “Unexpected untyped word std_threading when expecting a variable Parsing failed due to invalid input!”). If I don’t create and run a thread opcode runs fine.
That’s Ok, there is a cinflict betwee the “_CR” definition in the standard C++ library and in Csound, although it’s only an issue on Windows from what I can tell. If you undef _CR before including any Csound headers it should be fine. With regards to the std::thread issue, I just checked an opcode I wrote that uses it, and this is how my include section looks:
#undef _CR #include <plugin.h> #include
I don’t think you need to worry about redefining _CR as it will be redefined elsewhere. I guess if pthread works ago, you might as well use that? But you have to link to the pthread library which is a little annoying.
There are few sentences in Victor’s paper to this topic (that I’ve overseen ) :
4.3. Memory Allocation
Csound provides its own managed heap for dynamic memory allocation. ....
It is not advisable for developers to employ any other memory allocation methods. ....
Well that couldn’t be clearer. So no std::vectors but csnd::AuxMem and csnd::Vector
6. Multithreading Support
The Csound API includes an interface for multithreading, which is implemented via pthreads [28] on POSIX systems, or other native threading libraries in non-POSIX platforms.
To allow opcodes an object-oriented access to this C interface, CPOF provides the Thread pure virtual class. ....
So no std::thread but csnd::Thread (or pthread)…
" I guess if pthread works ago, you might as well use that?" → Yes, it’s just that std::jthread is much more convenient but csnd::Thread and pthread will suffice