TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Francois Thunus
from: David Noon
date: 1996-06-18 21:02:04
subject: semaphore

On Sunday, 96/06/16, Francois Thunus wrote to All about "semaphore" as
follows:

FT> I don't want 2 copies of my program to run at the same time.
FT> I use DosCreateMutEx to create a semaphore when starting 
FT> the program, and DosDeleteMutEx when I'm done. or do I ?. 

Hi Francois,

For a single resource, in this case your program, a mutex semphore is
correct. A semaphore is destroyed when the last handle using it is
closed.

So your strategy is to attempt to create the semaphore, with the
obtain option coded. If the create fails, open the semaphore to obtain
a handle and then wait on it (this will be for the 2nd and subsequent
active instances of the program). At the end of the program close the
semaphore, which will unblock the next instance of the program if there
is one. They should queue in a FIFO manner. The last closure will
destroy the semaphore.

If you've done any assembler programming on IBM mainframes then the
ENQ and DEQ macros of MVS will provide you with a very good background
in how mutex semaphores work.

FT> Should I use DosCreateMuxWaitSem
FT> instead ?

No. Muxwait semaphores are for multiple resources and/or events.

Regards

Dave


 * KWQ/2 1.2i * Those who can, do.  Those who can't, supervise!

--- Maximus/2 3.01
* Origin: DoNoR/2,Woking UK (44-1483-725167) (2:440/4)
SEEN-BY: 50/99 270/101 620/243 625/100 711/401 409 410 413 430 808 809 934
SEEN-BY: 711/955 712/407 515 517 628 713/888 800/1
@PATH: 440/4 141/209 270/101 712/515 711/808 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.