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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Operating System Mutex

Operating System Mutex

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
4 Posts 3 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.
  • T Offline
    T Offline
    Tristan Rhodes
    wrote on last edited by
    #1

    Hi Guys, I can't seem to find any articles on how the OS Mutex's behave if they are not closed. I'm looking to use a mutex handle to check whether there are instances of various applications open prior to running an installer, but one of the apps is a C++ app, and in the event of a catastrophic failure, it may end a process without releasing the underlying Mutex. What effect would this have on the system? Would the Mutex state be invariant, or does ending the holding process free the mutex as well? Regards Tris

    ------------------------------- Carrier Bags - 21st Century Tumbleweed.

    _ R 2 Replies Last reply
    0
    • T Tristan Rhodes

      Hi Guys, I can't seem to find any articles on how the OS Mutex's behave if they are not closed. I'm looking to use a mutex handle to check whether there are instances of various applications open prior to running an installer, but one of the apps is a C++ app, and in the event of a catastrophic failure, it may end a process without releasing the underlying Mutex. What effect would this have on the system? Would the Mutex state be invariant, or does ending the holding process free the mutex as well? Regards Tris

      ------------------------------- Carrier Bags - 21st Century Tumbleweed.

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      Please use the documentation of CreateMutex[^] as a reference. The mutex will be automatically released when the process terminates. Here is a snippet from the documentation - The system closes the handle automatically when the process terminates. The mutex object is destroyed when its last handle has been closed. The documentation makes some recommendations to check for application instances. Here is a snippet that explains this - If you are using a named mutex to limit your application to a single instance, a malicious user can create this mutex before you do and prevent your application from starting. To prevent this situation, create a randomly named mutex and store the name so that it can only be obtained by an authorized user. Alternatively, you can use a file for this purpose. To limit your application to one instance per user, create a locked file in the user's profile directory.

      «_Superman_» I love work. It gives me something to do between weekends.

      T 1 Reply Last reply
      0
      • T Tristan Rhodes

        Hi Guys, I can't seem to find any articles on how the OS Mutex's behave if they are not closed. I'm looking to use a mutex handle to check whether there are instances of various applications open prior to running an installer, but one of the apps is a C++ app, and in the event of a catastrophic failure, it may end a process without releasing the underlying Mutex. What effect would this have on the system? Would the Mutex state be invariant, or does ending the holding process free the mutex as well? Regards Tris

        ------------------------------- Carrier Bags - 21st Century Tumbleweed.

        R Offline
        R Offline
        Rajesh R Subramanian
        wrote on last edited by
        #3

        If nobody owns up for a mutex (orphaned), the OS immediately closes it. Also, locked file idea suggested in the docs may not be very helpful if you want your application to be truly one-instance (across logins). But, in such a case, only a kernel object (like Mutex) can help you.

        It is a crappy thing, but it's life -^ Carlo Pallini

        1 Reply Last reply
        0
        • _ _Superman_

          Please use the documentation of CreateMutex[^] as a reference. The mutex will be automatically released when the process terminates. Here is a snippet from the documentation - The system closes the handle automatically when the process terminates. The mutex object is destroyed when its last handle has been closed. The documentation makes some recommendations to check for application instances. Here is a snippet that explains this - If you are using a named mutex to limit your application to a single instance, a malicious user can create this mutex before you do and prevent your application from starting. To prevent this situation, create a randomly named mutex and store the name so that it can only be obtained by an authorized user. Alternatively, you can use a file for this purpose. To limit your application to one instance per user, create a locked file in the user's profile directory.

          «_Superman_» I love work. It gives me something to do between weekends.

          T Offline
          T Offline
          Tristan Rhodes
          wrote on last edited by
          #4

          Cheers, i wasn't entirely clear on whether the Mutex would self release after a Process exits from a catastrophic failure.

          ------------------------------- Carrier Bags - 21st Century Tumbleweed.

          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