Re: Limiting to one instance
"Chris Chapman" <[email protected]> Wed, 16 Aug 2006 10:14:20 +0100
| Newsgroups | gmane.games.devel.windows |
|---|---|
| Message-ID | <[email protected]> |
--===============0788763570== Content-Type: multipart/alternative; boundary="----=_Part_19783_32929993.1155719660457" ------=_Part_19783_32929993.1155719660457 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline It would seem like a combination of the two approachs avoids the drawbacks of either, no? Use a named mutex to protect the initialisation process, so that if FindWindow fails to find an existing window, the mutex is held until after the window is created. In a switch user case, the window will have long since been created, and so the mutex won't be held open. The logic becomes "no two users can start the application" rather than "no two users can run the application". Personally I've always used the named mutex alone to protect the app, and found it to be stable and robust; but I've never had to write a shipping PC title or deal with limited user cases... C Black Company Studios On 16/08/06, Richard Mitton <[email protected]> wrote: > > http://support.microsoft.com/default.aspx?scid=kb;en-us;106385 > > I guess it is an officially recommended technique. > A mutex is a proper kernel object, so should be pretty safe. > > -- > ()() Richard Mitton > ( '.') > (")_(") code jester .:. treyarch .:. [email protected] > > > > > On 16 Aug 2006, at 12:37 am, Alen Ladavac wrote: > > > Jon wrote: > >> Using FindWindow() introduces a possible race condition > > > > I stand corrected. I was using this for installers, not for actually > > preventing double-startup of the same app. So scratch my remark on > > FindWindow being useful here. > > > > Stefan wrote: > >> But CreateMutex etc *is* intended for the purpose. > > > > Well, I was replying to Andrew's comment on IP ports not being > > suitable for that purpose. In that context, I believe CreateMutex is > > not any more suitable. CreateMutex (named) is intended for the purpose > > of synchronizing two processes by actually using a mutex. Using the > > mutex's mere existance to note anything is as much of a hack as using > > an IP port for that. The fact that there are personal firewalls in the > > modern world is another hack as well. IP port creation was not > > supposed to be intercepted in this way - in the original design, > > AFAIK. > > > > Simply trying to point out the fact that we frequently have to use > > something for what it is not supposed to be used for. And often one > > can't predict all possible side-effects. Like that poor guy didn't > > predict that a firewall would make the IP-port solution useless, like > > FindWindow is not perfect due to a possible race condition, like the > > CreateMutex might have possible user-switching problem (although not > > likely, as local creation is default, IIRC). > > > > Put simply: unless the manual says "this can be used to do XYZ", then > > if you are using it for that, you are risking possible problems. > > (Although, you are probably risking possible problems even if it does > > say so. :p ) > > > > JM2C, > > Alen > > > > > > ---------------------------------------------------------------------- > > --- > > Using Tomcat but need to do more? Need to support web services, > > security? > > Get stuff done quickly with pre-integrated technology to make your > > job easier > > Download IBM WebSphere Application Server v.1.0.1 based on Apache > > Geronimo > > http://sel.as-us.falkag.net/sel? > > cmd=lnk&kid=120709&bid=263057&dat=121642 > > _______________________________________________ > > Gamedevlists-windows mailing list > > [email protected] > > https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows > > Archives: > > http://sourceforge.net/mailarchive/forum.php?forum_id=555 > > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job > easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > Gamedevlists-windows mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_id=555 > ------=_Part_19783_32929993.1155719660457 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline It would seem like a combination of the two approachs avoids the drawbacks of either, no? Use a named mutex to protect the initialisation process, so that if FindWindow fails to find an existing window, the mutex is held until after the window is created. In a switch user case, the window will have long since been created, and so the mutex won't be held open. The logic becomes "no two users can start the application" rather than "no two users can run the application". <br><br>Personally I've always used the named mutex alone to protect the app, and found it to be stable and robust; but I've never had to write a shipping PC title or deal with limited user cases...<br><br>C<br>Black Company Studios <br><br><div><span class="gmail_quote">On 16/08/06, <b class="gmail_sendername">Richard Mitton</b> <<a href="mailto:[email protected]">[email protected]</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> <a href="http://support.microsoft.com/default.aspx?scid=kb;en-us;106385">http://support.microsoft.com/default.aspx?scid=kb;en-us;106385</a><br><br>I guess it is an officially recommended technique.<br>A mutex is a proper kernel object, so should be pretty safe. <br><br>--<br>()() Richard Mitton<br>( '.')<br>(")_(") code jester .:. treyarch .:. <a href="mailto:[email protected]">[email protected]</a><br><br><br><br><br>On 16 Aug 2006, at 12:37 am, Alen Ladavac wrote: <br><br>> Jon wrote:<br>>> Using FindWindow() introduces a possible race condition<br>><br>> I stand corrected. I was using this for installers, not for actually<br>> preventing double-startup of the same app. So scratch my remark on <br>> FindWindow being useful here.<br>><br>> Stefan wrote:<br>>> But CreateMutex etc *is* intended for the purpose.<br>><br>> Well, I was replying to Andrew's comment on IP ports not being<br>> suitable for that purpose. In that context, I believe CreateMutex is <br>> not any more suitable. CreateMutex (named) is intended for the purpose<br>> of synchronizing two processes by actually using a mutex. Using the<br>> mutex's mere existance to note anything is as much of a hack as using <br>> an IP port for that. The fact that there are personal firewalls in the<br>> modern world is another hack as well. IP port creation was not<br>> supposed to be intercepted in this way - in the original design, <br>> AFAIK.<br>><br>> Simply trying to point out the fact that we frequently have to use<br>> something for what it is not supposed to be used for. And often one<br>> can't predict all possible side-effects. Like that poor guy didn't <br>> predict that a firewall would make the IP-port solution useless, like<br>> FindWindow is not perfect due to a possible race condition, like the<br>> CreateMutex might have possible user-switching problem (although not <br>> likely, as local creation is default, IIRC).<br>><br>> Put simply: unless the manual says "this can be used to do XYZ", then<br>> if you are using it for that, you are risking possible problems. <br>> (Although, you are probably risking possible problems even if it does<br>> say so. :p )<br>><br>> JM2C,<br>> Alen<br>><br>><br>> ---------------------------------------------------------------------- <br>> ---<br>> Using Tomcat but need to do more? Need to support web services,<br>> security?<br>> Get stuff done quickly with pre-integrated technology to make your<br>> job easier<br>> Download IBM WebSphere Application Server v.1.0.1 based on Apache<br>> Geronimo<br>> <a href="http://sel.as-us.falkag.net/sel">http://sel.as-us.falkag.net/sel</a>?<br>> cmd=lnk&kid=120709&bid=263057&dat=121642<br>> _______________________________________________ <br>> Gamedevlists-windows mailing list<br>> <a href="mailto:[email protected]">[email protected]</a><br>> <a href="https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows"> https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows</a><br>> Archives:<br>> <a href="http://sourceforge.net/mailarchive/forum.php?forum_id=555">http://sourceforge.net/mailarchive/forum.php?forum_id=555 </a><br><br><br>-------------------------------------------------------------------------<br>Using Tomcat but need to do more? Need to support web services, security?<br>Get stuff done quickly with pre-integrated technology to make your job easier <br>Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo<br><a href="http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642">http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 </a><br>_______________________________________________<br>Gamedevlists-windows mailing list<br><a href="mailto:[email protected]">[email protected]</a><br><a href="https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows"> https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows</a><br>Archives:<br><a href="http://sourceforge.net/mailarchive/forum.php?forum_id=555">http://sourceforge.net/mailarchive/forum.php?forum_id=555</a><br></blockquote> </div><br> ------=_Part_19783_32929993.1155719660457-- --===============0788763570== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 --===============0788763570== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Gamedevlists-windows mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows Archives: http://sourceforge.net/mailarchive/forum.php?forum_id=555 --===============0788763570==--