TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Darin McBride
from: Mike Bilow
date: 1996-05-21 23:28:54
subject: Semaphores (16 & 32)

Darin McBride wrote in a message to All:

 DM>         I'm trying to block Sq386p.exe which uses
 DM> \SEM\SQUISH\DEFAULT, however the Semaphores included in the
 DM> Warp toolkit want me to use \SEM32\ to start.  Can I just
 DM> use \SEM\ anyway?

Semaphores accessed by the old 16-bit API calls use the "\SEM\" names.

 DM>         Since I'm using Watcom (10.6), I have the PRCP.INF
 DM> file which, handily, has DosCreateSem which wants to use
 DM> \SEM\ instead.  I thought, "Great!  I'll just use that!" 
 DM> Watcom's compiler tells me that these aren't in the header
 DM> files (the ones that come with Watcom, nonetheless!), so too
 DM> bad.  Ack!  Not in the Warp Toolkit headers either, it
 DM> seems.  I created the function prototypes, having noticed
 DM> that these functions were in OS2286.LIB, and linked with
 DM> that lib (in the 386 directory), but the linker complains
 DM> that they are undefined references.  Somehow I'm guessing I
 DM> need those, but...

 DM> Can anyone help me?

Well, you have several options.  You could write your program using the
16-bit OS/2 compiler included with Watcom C++, and then you be using the
header files from \WATCOM\H\OS21X.  This would work, and would probably be
reasonable for short, simple programs.

Another approach would be to write the necessary function prototypes
manually, including the "_far16" and "_Seg16" extended
keywords as needed.  See the User's Guide for more information about how to
prototype and call a 16-bit function from 32-bit code.  The compiler will
generate the necessary thunk.

 DM> When I create my own semaphore to block other copies of myself, 
 DM> I'll want to use the 32-bit semaphores, and, again, I'd like a 
 DM> little direction on what to use: the Mutex semaphores?  If so, 
 DM> can someone give me really simple sample code? 

Yes, use mutex semaphore to enforce mutual exclusivity.  You can use the
16-bit semaphores for simplicity if you choose, rather than mix 16-bit and
32-bit semaphores.  You lose certain functionality with the 16-bit
semaphores, especially support for multiplex semaphores.

 DM> While I'm experienced with C/C++, I have never gotten in
 DM> this much detail with OS/2 before.  I understand DLLs, API
 DM> calls, classes, modularity, etc., however, so it doesn't
 DM> have to be *too* basic on a technicality scale. 

There are extensive examples supplied with the Watcom C++ compiler,
provided you chose to install them, in \WATCOM\SAMPLES\TOOLKT2X\C\SEMAPH.

 DM> Perhaps after I learn semaphores, I'll go on to
 DM> multi-threading.  :-)   

This stuff is not rocket science.  It just requires time and effort to learn.
 
-- 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 711/401 409 410 413 430 808 809 934 955
SEEN-BY: 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™.