none
simple inter-thread communication RRS feed

  • Question

  • I have data packets being recieved by two different threads within an application.

    Both threads use a common thread to decode the incoming packet.

    Currently, I use a mutex to co-ordinate so that the common thread can copy from one of the source threads or the other.

    What I would like to do is comething like UDP send()/receive() without having to do the maintenance work.  This way, both source threads simply throw the incoming data packets onto a stack maintained by a system or .net service.  (seems like overkill.)

    Win32 SendMessage/ReceiveMessage only passes a pointer to the data buffer, does not send the data buffer itself.

    What is the simplest API to perform this?

    Boyd


    BDM

    Thursday, December 19, 2013 7:59 PM

Answers

All replies

  • Hi Boyd,

    Sounds like you are looking for Memory-Mapped Files, which are supported in NET 4.0 BCL. You can use managed code to access memory-mapped files in the same way that native Windows functions access memory-mapped files, as described in Managing Memory-Mapped Files in Win32 in the MSDN Library. See the following link for details. http://msdn.microsoft.com/en-us/library/dd997372.aspx.

    If I misunderstand you, please let me know.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, December 20, 2013 2:57 AM
    Moderator
  • Hetro,

    Thanks for the response.

    I use Memory Mapped Files.  It gives a shared memory block.  I could do it that way, but then I have to write the send/receive protocol.

    I was hoping there was something like SendMessage that sends a data block, not just a pointer to the data block.

    Boyd


    BDM

    Friday, December 20, 2013 2:24 PM
  • Hi Boyd,

    When you create Memory-Mapped files, any thread can access it as common file. Why you have to write protocol for it? Am I missing something? Could you please provide more about this?

    At last, I pick up an article about working with memory mapped files in .NET 4.

    http://blogs.msdn.com/b/salvapatuel/archive/2009/06/08/working-with-memory-mapped-files-in-net-4.aspx.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, December 24, 2013 3:27 AM
    Moderator
  • [...]

    Win32 SendMessage/ReceiveMessage only passes a pointer to the data buffer, does not send the data buffer itself.

    What is the simplest API to perform this?


    Consider SendMessage and WM_COPYDATA.


    Tuesday, December 24, 2013 6:25 PM