TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Francois Thunus
from: Mike Bilow
date: 1996-06-17 23:00:42
subject: semaphore

Francois Thunus wrote in a message to All:

 FT> a stupid question:
 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 the
 FT> program, and DosDeleteMutEx when I'm done. or do I ?. Should
 FT> I use DosCreateMuxWaitSem instead ?
 FT> My question is:
 FT> what is a good way to put so to speak copy 2 on hold until
 FT> copy 1 is done ? I have to check periodically for the
 FT> semaphore, else just wait. When the semaphore is gone, then
 FT> I can safely resume. Is there a way to do this without
 FT> consuming any resources ? the doc talks about threads for
 FT> the muxwait, which is why I am not sure I can use it between
 FT> 2 apps.

First, you are getting "multiplex" (which you don't want)
confused with "mutex" (which you do want).

Choose a semaphore name which will be the same for all instances of your
process.  Your program needs to Create or Open the named semaphore.  The
first instance must Create while all later instances must Open; the usual
approach is to attempt to Create and, if it fails, attempt to Open.

Once a handle is obtained from either Create or Open, you Request the
semaphore.  A successful Request results in the semaphore being
"owned" by the requesting thread until it Releases the semaphore.
 Request/Release are the main operations performed on a mutex semaphore. 
If a Request is made for a semaphore while it is "owned" by
another thread, then the Request call will wait and consume almost no
system resources until either the semaphore becomes unowned or the timeout
specified in the Request call expires.
 
-- Mike


--- 
* Origin: N1BEE BBS +1 401 944 8498 V.34/V.FC/V.32bis/HST16.8 (1:323/107)
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: 323/107 396/1 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™.