Sie sind auf Seite 1von 2

Global Semaphores in a Parallel Programming Environment

P. Theodoropoulos, P° Tsanakas and G. Papakonstantinou

National Technical University of Athens


Dept. of Electrical and Computer Engineering
Zografou Campus, Zografou 15773, Athens, Greece
e-mail: ptheod, panag, papakon @dsclab.ece.ntua.gr

A b s t r a c t . In this paper we present a global semaphores mechanism, and ported on


various parallel programming environments, The whole mechanism is available as a
library for the C programming language and some additional include files. The parallel
applications programmer uses these functions in order to construct transparent
synchronization schemes in a wide variety of parallel processing systems.
Keywords: Parallel programming, Synchronization, Global semaphores.

1 Introduction
In 1965 Dijkstra [1], in order to resolve the critical section problem in concurrent
programming, introduced the concept of semaphores. He defined two basic functions
on them, P and V, considered to be executed indivisibly. The primary functions of
semaphores include the synchronization of processes and the mutual exclusion of
critical sections. Moreover, semaphores can assist in solving traditional operating
systems problems like resource sharing. Their implementation, however, in a
distributed programming environment is not straightforward, since there exists no
central control over the running processes.
Global semaphores, in a parallel programming environment, refer to
primitive functions that enable the syncronization of processes running on different
processors, possibly on different machines connected via a communication network.
In this context, a parallel programming platform is required to support communication
between all processes (on all processors) in a transparent way. Consequently, the
union of all processors on all different machines is viewed as a single "virtual
machine". Such parallel programming platforms are PVM[2], MPI[3] and Orchid[4].
The particular implementation of global semaphores is addressed to parallel
programming environments with distributed memory, where message passing is used
as the basic synchronization mechanism. It is well known that message passing is
equivalent to the semaphores mechanism and with the monitor structures as well, since
all three mechanisms can be used in process syncronization and critical section mutual
exclusion [5][6]. The semaphores mechanism, however, is more generic and more
practical than message passing, since it allows an arbitrary number of processes to be
synchronized, by controlling the execution of their code without the need to know the
exact ids or the particular role of the other participating processes.
The significance of the process synchronization mechanism for the protection
of critical sections or resource sharing is evident from the continuing research in the
152

field. Illustratively, in [7] the efficiency of various locking schemes and mutual
exclusion mechanisms are discussed and compared. Furthermore, the various shared
memory consistency models require some general synchronization primitives in order
to simplify their programming [8]. Semaphores represent a tested solution that
resolves these problems with the optimal method in most cases.
Only few parallel programming systems exhibit mechanisms with an
equivalent functionality to the semaphores. For example, the Clouds[9] system that
also offers semaphores, implements their mechanism as part of its distributed memory
model, leaving to the programmer the responsibility of making the necessary memory
updates and, subsequently, informing all the other processes about them. This sort of
synchronization capabilities is also missing from most distributed operating systems.
As an example, Amoeba provides the capabilities for synchronization among threads
only, and not among processes [10]. These threads belong to a single process, share
the same virtual address space and are all scheduled to run on the same processor.
In the current paper, the implementation of the global semaphores
mechanism over three parallel programming platforms (PVM, MPI, Orchid) is
presented. The proposed implementation is quite general and gives the parallel
programming platforms synchronization capabilities that are missing from most of the
existing systems. In the beginning, a description of the general principles that control
the design of this mechanism is presented. Next, we outline the calls provided to the
parallel application programmer. Finally, the implementation details are given, along
with an evaluation of the various actual implementations.

2 General Description
The general features of the proposed global semaphores mechanism correspond to
their distributed management and the effective handling of the requests for semaphore
operations with the minimum possible overhead. The basic idea of the proposed
implementation is the reduction of a global semaphore operation to an appropriate
operation on an ordinary semaphore. For this purpose, a special process (global
semaphore server) is running on every processor. Every server maintains a list of all
the semaphores that were created on its host processor. Each element of the list
consists of the semaphore's name, id, current reference count, current value, a pointer
to the semaphore's waiting queue and, finally, a pointer to the next element in the list.
To address a semaphore within the virtual machine, the global semaphore
library uses a semaphore descriptor. This descriptor identifies uniquely any global
semaphore already opened. For purposes of efficiency, it is made to fit into the largest
data type available on a wide range of machines (long integer - 32 bits long). In the
descriptor, two items are coded. The first is the id of the processor where the owner
semaphore server is running. The second is used by the owner server as an id of the
global semaphore, to identify and distinguish it from the other semaphores it owns.
The proposed design and implementation is addressed to parallel
programming environments, as it is assumed that every processor in the virtual
machine can be identified by a unique identifier and that global semaphores or global
semaphore servers do not migrate. In a distributed environment, on the contrary,
resources are handled in a transparent way, so that the end user and the programmer

Das könnte Ihnen auch gefallen