Browse Prior Art Database

Algorithm to Support the Emulation of UNIX semget() System Call in the OS/2 Operating System

IP.com Disclosure Number: IPCOM000110782D
Original Publication Date: 1994-Jan-01
Included in the Prior Art Database: 2005-Mar-26
Document File: 4 page(s) / 112K

Publishing Venue

IBM

Related People

Hidalgo, DS: AUTHOR [+3]

Abstract

Disclosed is an invention which provides an algorithm that can be used to obtain a very close emulation of the UNIX* semget() system call in the OS/2** operating system. The emulation of UNIX system calls is an accepted approach to porting UNIX C source code to OS/2. The differences in semaphore semantics between these two operating systems makes the emulation of UNIX semaphore system calls particularly challenging.

This text was extracted from an ASCII text file.
This is the abbreviated version, containing approximately 46% of the total text.

Algorithm to Support the Emulation of UNIX semget() System Call in
the OS/2 Operating System

      Disclosed is an invention which provides an algorithm that can
be used to obtain a very close emulation of the UNIX* semget() system
call in the OS/2** operating system.  The emulation of UNIX system
calls is an accepted approach to porting UNIX C source code to OS/2.
The differences in semaphore semantics between these two operating
systems makes the emulation of UNIX semaphore system calls
particularly challenging.

      An approach used to port program code written for UNIX
platforms to other operating systems such as OS/2 is to emulate the
UNIX system calls in those operating systems, along with all the
necessary semantics of those calls and the necessary header file
definitions expected by the ported source code.  Some UNIX system
calls are easier to emulate in OS/2 than others.  Of particular
interest are the emulation of the UNIX semaphore system calls.  UNIX
semaphore system calls have significantly different semantics from
those of OS/2 semaphores.  There is no direct correspondence between
any type of OS/2 semaphore and a UNIX semaphore.

      This invention provides an algorithm that can be used to obtain
a very close OS/2 emulation of the UNIX semget() system call that is
used to allocate an array of UNIX semaphores, also known as semaphore
sets.  The algorithm is based on a separately disclosed data
structure scheme that provides an abstracted OS/2 representation of a
single UNIX semaphore, and a set of UNIX semaphores.  The detailed
algorithm for an OS/2 emulation of the UNIX semget() system call is
shown below.  The creating process by default opens the semaphores
for all of its threads.
int semget (key_t key, int sem_count, int sem_flag)
BEGIN

  Use the key to build the shared memory name.

  Check to see if the semaphore shared memory already exists.

  IF the shared memory already exists THEN

  BEGIN

    Get the address of the allocated semaphore Control Block (CB).

    Try to open the semset latch semaphore.

    IF Successful THEN

    BEGIN

      IF error opening the latch semaphore then this means that

         the semaphore set is still being created.  This protects the

         window in between the completion of the DosAllocSharedMem()
         by the creating thread, and the completion of the OS/2
function
         DosCreateMutexSem() call by that thread.

      THEN BEGIN

         Set errno = ENOENT.

         Disconnect from the shared memory.

         Return -1.

      END

      Try to lock the SET latch semaphore.

        This protects the window in between the completion of the
        DosCreateMutexSem() call (for the semset latch) by the
        creating thread and the completion of the last
        DosCreateMutexSem() call for the semaphore arrays by that
        thread...