Re: How to allow a specific number of Instances of my app?




"expvb" <nobody@xxxxxxx> wrote in message
news:u7G6aJ8%23GHA.4712@xxxxxxxxxxxxxxxxxxxxxxx
<snipped>

I agree with you that if an application crashes, all bets are off since
MSDN
documentation is usually not clear about this, but in this case it seems
that the mutex is closed when the application crashes. The reason I think
that this is the case is that VB6 itself creates a mutex or semaphore
object
with the full EXE name, which is used to provide App.PrevInstance
functionality. One can see the mutex/semaphore created by VB6 by using
Process Explorer:

http://www.sysinternals.com/Utilities/ProcessExplorer.html

In one test, it showed the following object:

Type: Semaphore
Name: \BaseNamedObjects\C:?TEST?PROJECT1.EXE

If the mutex/semaphore is not closed when the application crashes, then
crashed VB6 apps cannot be run without restarting the computer.


There is a bit of hesitation as it has been years since I piddled around
with the guts of VB, so I may be mistaken...

I doubt that VB implements App.PrevInstance using a Mutex/Semaphore as it is
so easily fooled. That's why the 'work-around', a Mutex, is often suggested
as a more reliable mechanism.

Also I have through-out my wobbly career created apps which crashed and
could not be restarted without re-booting the system. Now whether or not
that had anything to do with Semaphores, Mutexs, or just bad programming I
have no idea (but strongly suspect the latter. <g>).

Another issue to consider is that the 'mutex' provided by Win32Api isn't a
'real' kernel mutex; it is what the micro-geeks call a 'mutant', what ever
the heck that is. There is always about 5 to 12 layers of indirection
between here and there in VB.

It is hard to see how Windows would go about preserving a 'Mutex' if the
owning thread goes away. (In other words how would the OS *know* to close it
unless it is part of ending the thread?) So, is there such a thing as an
orphan thread in Windows? I don't know.

It gets damn complicated - After all, the whole process is amazing magic
when examined in depth - that is, it is hard enough to track what the heck
is going on when it all goes well - let alone know what happens when it
doesn't. <g>

-ralph



.



Relevant Pages

  • Re: How to allow a specific number of Instances of my app?
    ... is the responsibility of an App to remove the Mutex to allow another ... I think if the application crashes, the handle to the mutex is closed, ... I agree with you that if an application crashes, all bets are off since MSDN ... One can see the mutex/semaphore created by VB6 by using ...
    (microsoft.public.vb.general.discussion)
  • Re: How to allow a specific number of Instances of my app?
    ... I think if the application crashes, the handle to the mutex is ... the handle automatically when the process terminates. ... But the OP was talking about a "Crash". ...
    (microsoft.public.vb.general.discussion)
  • Re: How to allow a specific number of Instances of my app?
    ... I think if the application crashes, the handle to the mutex is ... the handle automatically when the process terminates. ... But the OP was talking about a "Crash". ...
    (microsoft.public.vb.general.discussion)
  • Re: How to allow a specific number of Instances of my app?
    ... is the responsibility of an App to remove the Mutex to allow another ... I think if the application crashes, the handle to the mutex is closed, but I ...
    (microsoft.public.vb.general.discussion)
  • Re: [PATCH 1/19] MUTEX: Introduce simple mutex implementation
    ... > a mutex was a sensible implementation tradeoff. ... are really counting semaphores, ... >> acceptable patch that introduces a separate data structure. ... > general semaphore, because a mutex has stronger invariants. ...
    (Linux-Kernel)