🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #14741

CreateFileMapping - atomic?

#14741
From: Paul
Date: Mon, 04 Aug 2003 12:29
19 lines
2127 bytes
I have a system that can contain any number of applications that may
communicate through shared memory.  Since I don't know in advance which apps
will be running at any given time, I would like to have all apps, upon
startup, attempt to create the common shared memory region for
communications.  If it already exists, a valid handle will be returned and
the app will just use it.  On the other hand, if it doesn't already exist,
the app will attempt to create it.

What happens if two apps simultaneously call the CreateFileMapping function?
Could a race condition occur as each one attempts to create the same region?
Am I guaranteed that only 1 will succeed and the other will return a valid
handle?  Could I ever get a case where one succeeds and the second fails
without a valid handle?  Are there any problems that may occur that I am not
considering?  I'd like to avoid designating an application to create shared
memory.

Does the same hold true for named mutexes?  Could a race condition ever
occur if I attempt to create the same mutex in two different processes at
the same time?
Technical Details
Message-ID: <3f2e51ac$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!newshosting.com!news-xfer2.atl.newshosting.com!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,df3e866e370eedca,start
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-08-04 05:40:03 PST
Reply-To: "Paul" <paul.anderson@jhuapl.edu>
From: "Paul" <paul.anderson@jhuapl.edu>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: CreateFileMapping - atomic?
Date: Mon, 4 Aug 2003 08:29:34 -0400
Lines: 21
Organization: JHU/APL
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 128.244.21.78
Message-ID: <3f2e51ac$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1060000172 128.244.21.78 (4 Aug 2003 05:29:32 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!newshosting.com!news-xfer2.atl.newshosting.com!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail