"how to implement a unmanaged thread-safe collection when i get this error: <mutex> is not supported when compiling with /clr</mute>" Code Answer

5

it is not supported because the std::mutex implementation uses getcurrentthreadid(). that's a winapi function that is not supposed to be use in managed code since it might be running on a custom clr host that doesn't use threads to implement threading.

this is the good kind of problem to have, it shows that you are building your code wrong. your native c++ is being compiled with /clr in effect. which works rather too well, all c++03 compliant code can be compiled to msil and get just-in-time compiled at runtime, just like managed code. you don't want this to happen, your native c++ code should be compiled to machine code and get the compile-time code optimizer love.

turn off the /clr option for this source code file, and possibly others, in your project. right-click + properties, general. if the mutex appears in the .h file that you have to #include in a c++/cli source file then you have a bigger problem, use an interface or pimpl to hide implementation details.

By friggle on April 8 2022

Answers related to “how to implement a unmanaged thread-safe collection when i get this error: <mutex> is not supported when compiling with /clr</mute>”

Only authorized users can answer the Search term. Please sign in first, or register a free account.