Operating System Mutex
-
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.
-
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.
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.
-
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.
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
-
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.
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.