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.


     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 )

 Source: NWSEM.PRG

 Author: Glenn Scott


7 responses to “FT_NWSEMLOCK

  1. Pingback: FT_NWSEMWAIT | Viva Clipper !

  2. Pingback: FT_NWSEMUNLOCK | Viva Clipper !

  3. Pingback: FT_NWSEMSIG | Viva Clipper !

  4. Pingback: FT_NWSEMOPEN | Viva Clipper !

  5. Pingback: FT_NWSEMEX | Viva Clipper !

  6. Pingback: FT_NWSEMCLOSE | Viva Clipper !

  7. Pingback: FT NetWare | Viva Clipper !

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.