Article View: borland.public.cppbuilder.nativeapi
Article #11095synchronizing access to named mutexes
From: Dennis Jones
Date: Fri, 27 Feb 2004 02:22
Date: Fri, 27 Feb 2004 02:22
32 lines
2514 bytes
2514 bytes
Hi, I recently wrote a DLL that communicates with one of my EXE's via shared memory. The DLL is used by a third-party program and provides a means by which the third-party application can communicate with my EXE. Communication between the DLL and EXE works beautifully once communication has been established. When the third-party application calls a function in my DLL, my DLL creates an inheritable memory-mapped file handle, then calls CreateProcess to start my EXE and passes the memory-mapped file handle to my EXE as a command-line parameter. The EXE opens the memory-mapped file using the inherited handle and begins to wait for commands from the DLL. Communications synchronization is managed with a pair of named mutexes. After calling CreateProcess to start the EXE, the DLL sleeps for 1 second before sending any commands to the EXE, which typically gives the EXE enough time to load and open the memory-mapped file and named mutexes. However, I am concerned that 1 second won't always be long enough in some cases, and although not a big deal, 1 second might be more than is really necessary in other cases. If the DLL sends a request by signaling a mutex before the EXE has had a chance to open the mutex, then even after the EXE has opened the mutex, the EXE will not see that the mutex has been signaled, and consequently will never respond to the command. So my question is, how can the DLL know when the EXE has opened the memory-mapped file and named mutexes, and is ready to begin receiving requests? Thanks, - Dennis
Technical Details
Message-ID:
<403ea9c9$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-09!supernews.com!diablo.theplanet.net!newsfeed.icl.net!newsfeed.frii.net!newsfeed.frii.net!news.compaq.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,147e3de49808f5a,start X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2004-02-26 18:49:20 PST From: "Dennis Jones" <djones@nospam.com> Newsgroups: borland.public.cppbuilder.nativeapi Subject: synchronizing access to named mutexes Date: Thu, 26 Feb 2004 18:22:02 -0800 Lines: 34 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 204.200.27.7 Message-ID: <403ea9c9$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1077848521 204.200.27.7 (26 Feb 2004 18:22:01 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-09!supernews.com!diablo.theplanet.net!newsfeed.icl.net!newsfeed.frii.net!newsfeed.frii.net!news.compaq.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail