Darin McBride
just releases new REXXSEM (REXX extentions: 16-bit and 32-bit semaphores, plus
functions to help wordwrap, find process IDs, and open Netscape windows). The archive
(rxsem06b.zip, 59.47K) was uploaded on Hobbes.
REXXSEM - WHY!?!?!?
-------------------
by Darin McBride
After years of using REXX and months trying to get multiline
support for my BBS in REXX, I got fed up. I wanted semaphore support -
both to interface with Squish (which uses 16-bit semaphores) and
everything else (using 32-bit semaphores which will be faster under
OS/2 2.0+). I wanted to prevent programs which were too dumb to
provide their own semaphoring from running simultaneously with each
other. And here's the rexx routines I came up with. If they help you,
I'd be happy to know. If there are some extentions you would like to
see, let me know as well. And if you would like to offer some example
rexx scripts, that would be great, too.
What REXXSEM does
REXXSEM is a REXX-extention DLL. That is, it is a DLL that is
written to allow REXX scripts to call it. This works similar to the
REXXUTIL that come with OS/2's REXX.
The REXXUTIL were written to give basic access to some very
useful OS/2 API functions dealing with file systems, WPS, and other
areas. REXXSEM was written to give basic access to some other very
useful OS/2 APIs: the mutual-exclusion (mutex) semaphores.
REXXSEM's semaphores, then, work the same way as the OS/2 API
semaphore functions. This includes using OS/2's ability to block your
REXX script until the desired semaphore is available (to use zero CPU
cycles while waiting), priority-based scheduling (if a high-priority
program is waiting on your semaphore, you will get its priority until
you release the semaphore), and priority-based semaphore ordering (the
highest priority thread that is waiting for a semaphore will get it
next).
When to use REXXSEM
The "old" (DOS?) way of finding out whether another script is
running is to look for a "semaphore" file. If it doesn't exist, create
it and continue. If it does exist, wait a second and look again in a
loop until it no longer exists. When you're done, delete the file.
This is tedious, error prone, and CPU (and disk!) intensive.
Every time you want to do this, you need to write your code out, and,
if you code like me, you'll forget something different each time,
ensuring a fun time debugging.
This is where other languages excel: they allow you to call the
OS's semaphores. Well, now you can do the same thing in REXX.
Actually, you could before if you have ObjectREXX which has
semaphoring functions built in. What I found is that ObjectREXX
couldn't perform at all on my old 486dx2/66. Since then, I haven't
switched back even though I have a faster machine. If you don't want
the overhead of ObjectREXX but want semaphores, this is the perfect
package.
What else?
REXXSEM does not have to abort your script with some cryptic
"bad function call" message. If you use the SemReturnValidAlways
function to turn this feature on, all functions will always return
valid, but will provide an explanation of what the problem is. In
fact, these messages can be translated and used in whichever language
you want, if I can find a translator from English to your language.
Mind you, these messages can get a little long for a single
string, so there is a WordWrap function to wrap the words at whatever
width you want (defaulting to the current session's width). (This may
not work well in a PM REXX session - but you can specify a width to
use.)
Other neat features added were the ability to open Netscape
windows ... without starting new procseses. OpenNetscapeWindow will
let you open a URL without starting new processes - a method that is
rapidly faster than just typing "start netscape <url>", and consumes
vastly less memory. You can specify whether to use an existing (OLD)
netscape window, or to have Netscape create a new (NEW) window.
Of course, somewhere in there the REXXSEM dll must determine
whether or not netscape is running, so I externalized part of this as
well: ProcessIDsOf will tell you all process ID's of any given process
name(s). You can find out how many CMD sessions are running, even
their process ID's (which may come in handy for other purposes later
on, such as killing them). This method is faster than using pstat with
rxqueue and reading it line-by-line if you just need to know whether
the process exists or not. It uses some new APIs to do this which
preclude pre-Warp OS/2, and even preclude some fixpaks of Warp 3.
Is there anything missing? Have a favourite function that
you'd like to see in a REXX DLL? If you have it written in
VAC-compatable code, send it in and I'll try to get it in!
How to use REXXSEM
REXXSEM uses standard REXX methods: put the dll in your libpath
somewhere, and read the reference (rexxsem.ref)!
(<phew>, that was easy. :-)
REXXSEM licencing
REXXSEM is distributed as licenced freeware. REXXSEM
("the Program") is copyright 1998 by the author and all rights are
reserved.
Under this licence, you may:
1. use the Program in binary form only.
2. make copies of the original file you downloaded and distribute it,
provided that you transfer a copy of this licence to the other party.
You may NOT:
1. reverse assemble, reverse compile, or otherwise translate the
program.
2. distribute the Program, in whole or in part, with any shareware or
commercial application.
A separate licence is available for licencing with shareware and
commercial distribution.
The author expressly disclaims all liabilities arising from the
use of the Program, including, but not limited to, (i) third-party
claims against you, (ii) loss of, or damage to, your records or data,
(iii) economic consequential damages (including lost profits or
savings) or incidental damages, even if the author is informed of their
possibility.
THERE ARE NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE.
You may not sell, transfer, assign, or subcontract any of your rights
or obligations under this license. Any attempt to do so is void.
This license is governed by the laws of Ontario, Canada.
REXXSEM'S AUTHOR
Darin McBride - longtime OS/2 abuser, longertime sysop.
Obviously he
enjoys causing himself headaches. If you have a cure for these
headaches, or just some general REXXSEM questions, you can contact him
as below:
EMail: dmcbride@globalserve.net
(preferred)
Darin.McBride@tower.to.org
Fidonet: <arf, arf!>
Netmail: Darin McBride, 1:250/102
Echos: C_ECHO, C_PLUSPLUS, OS2PROG (only on-topic in OS2PROG)
@Macarlo, Inc.
@Macarlo's Shareware & Web
OS/2
Java Lobby Member
Java Site Accredited
[TOP]
[HOME] [INDEX]