Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- SIx Driver RDD v3.00 - Reference Guide - <b>sx_makesem():</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
  Sx_MakeSem():

  Syntax:  Sx_MakeSem( [nOrder | cName] )

           nOrder = Position of index in list of indexes
           cName  = Name for the semaphore file

  Returns:   <numeric> Number of users for this semaphore file.
                  -1 if an error occurred.

  Description:    This function is used to create a semaphore file using
                  the name of an active index or a specified name.

                  A file is created using the specified name.  If an index
                  order is specified, then the name of that index is used
                  for the file.  The current index name (if any) is used if
                  no argument is supplied.  The default extension for
                  semaphore files is ".SEM".

                  If the specified semaphore file already exists, then the
                  user count for the file is incremented.  The value
                  returned represents the number of users for the specified
                  semaphore file (including current user).

                  Semaphore files are normally used to signal something to
                  others on a network who are sharing the same files or
                  resources.  The intention of Sx_MakeSem() and Sx_KillSem()
                  is to provide a simple mechanism for using semaphores in
                  conjunction with indexes, as well as more generic
                  semaphore uses.

  Example:

    /*
      This is a simple example showing the usage of the semaphore functions
      (Sx_MakeSem(), Sx_KillSem(), Sx_IsSem()).  Finding a practical use for
      this is left as an exercise for the programmer. <g>
    */

    #include "SIXCDX.CH"
    #include "INKEY.CH"

    LOCAL nKey, nSemCount := 0

    CLS

    // Draw the display
    @ 9,11 TO 15,67 DOUBLE
    @  9,30 SAY " SEMAPHORE EXAMPLE "
    @ 11,29 SAY "TEST.SEM exists?:"
    @ 13,29 SAY "User Count......:"
    @ 15,13 SAY " [F1] = Add User   [F2] = Remove User   [ESC] = Quit "

    // Show initial values
    @ 11,47 SAY iif( Sx_IsSem("TEST"), "Yes", "No " )
    @ 13,47 SAY nSemCount PICTURE "999"

    DO WHILE (nKey := Inkey(0)) != K_ESC

      DO CASE

        CASE nKey == K_F1                 // Add a user
          nSemCount := Sx_MakeSem("TEST")

        CASE nKey == K_F2                 // Remove a user
          IF nSemCount > 0
            nSemCount := Sx_KillSem("TEST")
          ENDIF

       OTHERWISE                          // Don't bother going any further
          LOOP

      ENDCASE

      // Show semaphore state
      @ 11,47 SAY iif(Sx_IsSem("TEST"), "Yes", "No ")
      @ 13,47 SAY nSemCount PICTURE "999"

    ENDDO

    CLS

    // See if the semaphore file is there
    IF (Sx_IsSem("TEST"))
      // Kill off remaining user count
      DO WHILE (Sx_KillSem("TEST") > 0)
      ENDDO
    ENDIF



See Also: Sx_KillSem() Sx_IsSem()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson