Mixed Code in C++ and C# RRS feed

  • Question

  •   We have a solution with some component in C# and some in C++.

       C++ DLL needs to write to some shared datastructure like queue and C# need to read from that queue.

       C++ writing would be from primary thread and reading threads would be from C#.

       Any idea which data structure to use which can provide concurrency control between c# and c++? any pointers? 

    Shahid Roofi

    Monday, November 18, 2019 8:57 AM

All replies

  • In my opinion, if C++ DLL is a “C++/CLR Class Library”, then it can be referenced by C# and you can use .NET objects in both of modules, such as Queue, ConcurrentQueue, Mutex, AutoResetEvent, etc.

    Otherwise, in C++, consider CreateMutex specifying some unique name for lpName parameter; also use WaitForSingleObject and ReleaseMutex during the queue operations.

    In C#, create a Mutex object specifying the same name; use WaitOne and ReleaseMutex functions during queue operations.

    • Edited by Viorel_MVP Monday, November 18, 2019 12:03 PM
    Monday, November 18, 2019 12:02 PM
  •  Make sense, let us try the same.

    Shahid Roofi

    Monday, November 18, 2019 12:10 PM
  • I posted a reply in your How to avoid thunks thread, I hope that helps.

    Sam Hobbs

    Friday, November 22, 2019 5:59 PM