Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Synchronization in a DLL

Synchronization in a DLL

Scheduled Pinned Locked Moved C / C++ / MFC
questionhardware
7 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VFaul
    wrote on last edited by
    #1

    I'm writing a DLL that can be accessed by multiple applications. The DLL talks to hardware (through a third-party driver). I need to block all other calls to the DLL while the DLL is talking to the hardware. What is the best synchrounization method - critical section, mutex,...? Also, I think the synchronization object in the DLL needs to be global so it can be accessed by multiple processes. How do I do that? Thanks, VF

    J I D 3 Replies Last reply
    0
    • V VFaul

      I'm writing a DLL that can be accessed by multiple applications. The DLL talks to hardware (through a third-party driver). I need to block all other calls to the DLL while the DLL is talking to the hardware. What is the best synchrounization method - critical section, mutex,...? Also, I think the synchronization object in the DLL needs to be global so it can be accessed by multiple processes. How do I do that? Thanks, VF

      J Offline
      J Offline
      jhwurmbach
      wrote on last edited by
      #2

      A critical section seems taylor-made for your requirements. No need to worry about where to allocate the synchonisation object: Your routines in the DLL do this before accessing the Hardware.


      Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
      George Orwell, "Keep the Aspidistra Flying", Opening words

      D 1 Reply Last reply
      0
      • V VFaul

        I'm writing a DLL that can be accessed by multiple applications. The DLL talks to hardware (through a third-party driver). I need to block all other calls to the DLL while the DLL is talking to the hardware. What is the best synchrounization method - critical section, mutex,...? Also, I think the synchronization object in the DLL needs to be global so it can be accessed by multiple processes. How do I do that? Thanks, VF

        I Offline
        I Offline
        Iain Clarke Warrior Programmer
        wrote on last edited by
        #3

        Critical sections won't work, as you can't operate on the same one across process boundaries. Using the Name part of CreateMutex looks like what you need. Saying that, its going to be very upsetting for program B if it suddenly freezes because program A is doing something. Back to the bad old days of Win 3.x... You may have legitimate need for this, but I would think *very* carefully about which functions you block... Iain.

        1 Reply Last reply
        0
        • V VFaul

          I'm writing a DLL that can be accessed by multiple applications. The DLL talks to hardware (through a third-party driver). I need to block all other calls to the DLL while the DLL is talking to the hardware. What is the best synchrounization method - critical section, mutex,...? Also, I think the synchronization object in the DLL needs to be global so it can be accessed by multiple processes. How do I do that? Thanks, VF

          D Offline
          D Offline
          DevMentor org
          wrote on last edited by
          #4

          if you're going to sync threads in the same process than work with critical section, they are the most efficient to share objects in multiple process, it is best to work with a mutex btw, mutex are global object system objects so if you sync on that you will be ok....if you need share data you can work with shared memory, but make sure that the DLL has APIs to both allcate and free the shared memory and the applications calls these API to allocate/free the memory otherwise you're going to have issues with memory leaks. read up on DLLs in MSDN and understand the limitation of passing object across DLL boundaries.

          Yours Truly, The One and Only!

          J 1 Reply Last reply
          0
          • J jhwurmbach

            A critical section seems taylor-made for your requirements. No need to worry about where to allocate the synchonisation object: Your routines in the DLL do this before accessing the Hardware.


            Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
            George Orwell, "Keep the Aspidistra Flying", Opening words

            D Offline
            D Offline
            dongxiaofei
            wrote on last edited by
            #5

            i:) support you

            1 Reply Last reply
            0
            • D DevMentor org

              if you're going to sync threads in the same process than work with critical section, they are the most efficient to share objects in multiple process, it is best to work with a mutex btw, mutex are global object system objects so if you sync on that you will be ok....if you need share data you can work with shared memory, but make sure that the DLL has APIs to both allcate and free the shared memory and the applications calls these API to allocate/free the memory otherwise you're going to have issues with memory leaks. read up on DLLs in MSDN and understand the limitation of passing object across DLL boundaries.

              Yours Truly, The One and Only!

              J Offline
              J Offline
              JudyL_MD
              wrote on last edited by
              #6

              _NightOwl_ wrote:

              to share objects in multiple process, it is best to work with a mutex

              It needs to be a named mutex. An un-named mutex is only good for multiple threads in the same process. Judy

              D 1 Reply Last reply
              0
              • J JudyL_MD

                _NightOwl_ wrote:

                to share objects in multiple process, it is best to work with a mutex

                It needs to be a named mutex. An un-named mutex is only good for multiple threads in the same process. Judy

                D Offline
                D Offline
                DevMentor org
                wrote on last edited by
                #7

                You are right Judy :) One should never use a mutex to sync threads in the same process. As I mentioned, critical sections are the best way to go for a multi-threaded process.

                Yours Truly, The One and Only!

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups