Perform a semaphore "lock"
FT_NWSEMLOCK ( <cSemaphore>, <@nHandle> ) -> lRet
<cSemaphore> is the name of a semaphore you want to "lock."
<nHandle> is the semaphore's handle, if you get the lock.
THIS MUST BE PASSED BY REFERENCE!
lRet == .t. if you get the lock, .f. if you don't.
If the lock succeeds, <nHandle> will contain the semaphore
handle. If it fails, the value of <nHandle> is undefined.
FT_NWSEMLOCK() uses the Nanforum Toolkit's NetWare Semaphore API
functions in order to provide a general purpose "lock" you can use in
a NetWare environment.
An interesting byproduct of NetWare's semaphore functions is
the "open count" which tells you how many connections have this
semaphore open. This is different from the semaphore's _value_,
which is set when the semaphore is opened and changed with
signal() and wait().
The point of semaphores is that you don't care how many users
are using the resource; you merely wait on a semaphore until
the resource becomes available or you give up. When you're done,
you signal it and off you go.
Back to the open count. FT_NWSEMLOCK() opens the semaphore
as named in <cSemaphore>. After it is opened, the open count
is checked. If it is anything other than 1, that means someone
else has it (or you failed in your open) so the semaphore is
closed and the "lock" is refused. If the value is 1, then your
app is that 1 station so the "lock" is granted.
You can use a semaphore lock to control access to anything
that Clipper's RLOCK() and FLOCK() can't help you with, such
as text files written with the low level file i/o functions,
LOCAL nHandle := 0
IF FT_NWSEMLOCK( "k:\apps\error.log", @nHandle )
// Note, you aren't actually LOCKING this file, you are
// just locking a semaphore by the same name. As long as
// all apps that might be using this file are cooperating
// with the same kind of semaphore lock, you can effectively
// control access to the file.
QOUT("Couldn't lock file.")
* Processing, then:
FT_NWSEMUNLOCK( nHandle )
Author: Glenn Scott
See Also: FT_NWSEMOPEN() FT_NWSEMEX() FT_NWSEMWAIT() FT_NWSEMSIG() FT_NWSEMUNLOCK()