Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

opensem(S)

waitsem(S)

sigsem(S)



     CREATSEM(S)              XENIX System V               CREATSEM(S)



     Name
          creatsem - Creates an instance of a binary semaphore.

     Syntax
          int = creatsem(sem_name,mode)
          char *sem_name;
          int mode;

     Description
          creatsem defines a binary semaphore named by sem_name to be
          used by waitsem(S) and sigsem(S) to manage mutually
          exclusive access to a resource, shared variable, or critical
          section of a program.  creatsem returns a unique semaphore
          number, sem_num, which may then be used as the parameter in
          waitsem and sigsem calls.  Semaphores are special files of 0
          length.  The filename space is used to provide unique
          identifiers for semaphores.  mode sets the accessibility of
          the semaphore using the same format as file access bits.
          Access to a semaphore is granted only on the basis of the
          read access bit; the write and execute bits are ignored.

          A semaphore can be operated on only by a synchronizing
          primitive, such as waitsem or sigsem, by creatsem which
          initializes it to some value, or by opensem which opens the
          semaphore for use by a process.  Synchronizing primitives
          are guaranteed to be executed without interruption once
          started.  These primitives are used by associating a
          semaphore with each resource (including critical code
          sections) to be protected.

          The process controlling the semaphore should issue:

               sem_num = creatsem("semaphore", mode);

          to create, initialize, and open the semaphore for that
          process.  All other processes using the semaphore should
          issue:

               sem_num = opensem("semaphore");

          to access the semaphore's identification value.  Note that a
          process cannot open and use a semaphore that has not been
          initialized by a call to creatsem, nor should a process open
          a semaphore more than once in one period of execution.  Both
          the creating and opening processes use waitsem and sigsem to
          use the semaphore sem_num.









     Page 1                                           (printed 8/7/87)





     CREATSEM(S)              XENIX System V               CREATSEM(S)



     Compatibility
          creatsem can only be used to define
           version 3.0 semaphores, not  System V semaphores.

     See Also
          opensem(S), waitsem(S), sigsem(S)

     Diagnostics
          creatsem returns the value -1 if an error occurs.  If the
          semaphore named by sem_name is already open for use by other
          processes, errno is set to EEXIST. If the file specified
          exists but is not a semaphore type, errno is set to ENOTNAM.
          If the semaphore has not been initialized by a call to
          creatsem, errno is set to ENAVAIL.

     Notes
          After a creatsem you must do a waitsem to gain control of a
          given resource.

          This feature is a XENIX specific enhancement and may not be
          present in all UNIX implementations.  This function must be
          linked with the linker option -lx.

































     Page 2                                           (printed 8/7/87)



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026