Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ sem_init(2) — DG/UX 5.4R2.01

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

sysconf(2)



sem_init(2)                  DG/UX 5.4 Rel. 2.01                 sem_init(2)


NAME
       sem_init - create or access a semaphore

SYNOPSIS
       #include <semaphore.h>

       int seminit (*sem, oflag, *name, pshared, value)
            semt     *sem;
            int       oflag;
            char      *name;
            int       pshared;
            int       value;

DESCRIPTION
       Use seminit(2) to create or attach to a semaphore:

        sem    is a pointer to the semaphore denoted by name that is
               returned by seminit.

        oflag  is O_CREAT to create the semaphore sem, or any other value to
               access sem without changing it.

        name   is a null-terminated string naming the semaphore, or NULL.

        pshared
               is the value 1. (This argument allows implementation-
               dependent extensions. At present, DG/UX supports no
               extensions.)

        value  is the initial value to assign to the semaphore.

       Semaphores are inherited on a fork(2).  Unlike files, they do not
       persist across a system reboot, and their names are not visible in
       the file system.

       Semaphores may be private or shared.  To create a private semaphore,
       specify oflag as O_CREAT and name as NULL.  A private semaphore is
       removed from the system when the creating process calls exit(2) or
       exec(2), or by a system reboot.

       To create a semaphore that can be shared, specify oflag as O_CREAT
       and supply a non-NULL name. Any process that knows the name will then
       be able to attach to the semaphore by calling seminit with the name
       and an oflag other than O_CREAT.  A shared semaphore remains in the
       system until it is rebooted, or until both of the following occur:

        * A process that knows the semaphore's name calls semunlink(2).
          (The process need not be attached to the semaphore.)

        * All processes attached to the semaphore call semdestroy(2),
          exit(2), or exec(2).

       The name may contain NAME_MAX characters (255 in DG/UX) not including
       the terminating NULL. DG/UX allows name to contain the slash



Licensed material--property of copyright holder(s)                         1




sem_init(2)                  DG/UX 5.4 Rel. 2.01                 sem_init(2)


       character, but other POSIX implementations may not. DG/UX places no
       restrictions on the contents of name, but for a name to be portable
       across conforming POSIX platforms, it must consist only of the
       characters comprising the portable filename character set.

       The value specified with this call affects the availability of a
       shared semaphore. A successful lock operation, with semlock(2) or
       semtrylock(2), decrements the value and semunlock(2) increments it.
       If the value is 0 or negative, the semaphore is unavailable.  In this
       case, semlock(2) blocks until the semaphore becomes available
       whereas semtrylock(2) returns with an error. Typical initial values
       specified with seminit(2) are 0 or 1.

       A process may have at most SEM_NSEMS_MAX semaphores open at once. Use
       sysconf(2) with argument _SC_SEM_NSEMS_MAX to get this system value.

   Note
        * This routine is based on POSIX realtime extension document P1003.4
          draft 12. It is therefore subject to change.

        * Compilation of a source file using this routine requires that
          feature macro _POSIX4_DRAFT_SOURCE be defined.  This feature macro
          is not enabled by any other feature macro, nor does it enable any
          other feature macro.

        * The compiled routine must be linked to library librte.a.

RETURN VALUE
       If successful, seminit returns 0. If unsuccessful, it returns -1 and
       sets ERRNO to one of the following:

        EFAULT Unable to access one of the parameters.

        EINVAL Unable to create the semaphore.

        EINVAL sem, name, or value is not valid.

        EINVAL pshared is not 1.

        ENAMETOOLONG
               name contains more than NAME_MAX characters.

        ENOENT sem does not exist and oflag is not O_CREAT.

        ENOSPC Unable to allocate enough memory.

        ENOSPC The calling process already has SEM_NSEMS_MAX semaphores
               open.

        ENOSPC No more POSIX semaphore IDs are available.

SEE ALSO
       semdestroy(2), semlock(2), semtrylock(2), semunlock(2),
       semunlink(2), sysconf(2).



Licensed material--property of copyright holder(s)                         2


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