Concurrent Pascal
Encyclopedia
Concurrent Pascal was designed by Per Brinch Hansen
Per Brinch Hansen
Per Brinch Hansen was a Danish-American computer scientist known for concurrent programming theory.-Biography:He was born in Frederiksberg, in Copenhagen, Denmark....

 for writing concurrent computing
Concurrent computing
Concurrent computing is a form of computing in which programs are designed as collections of interacting computational processes that may be executed in parallel...

 programs such as
operating system
Operating system
An operating system is a set of programs that manage computer hardware resources and provide common services for application software. The operating system is the most important type of system software in a computer system...

s and real-time monitoring systems on shared memory
Shared memory
In computing, shared memory is memory that may be simultaneously accessed by multiple programs with an intent to provide communication among them or avoid redundant copies. Depending on context, programs may run on a single processor or on multiple separate processors...


computers.

A separate language, Sequential Pascal, is used as the language for applications programs run by the operating
systems written in Concurrent Pascal. Both languages are extensions of Niklaus Wirth
Niklaus Wirth
Niklaus Emil Wirth is a Swiss computer scientist, best known for designing several programming languages, including Pascal, and for pioneering several classic topics in software engineering. In 1984 he won the Turing Award for developing a sequence of innovative computer languages.-Biography:Wirth...

's Pascal
Pascal (programming language)
Pascal is an influential imperative and procedural programming language, designed in 1968/9 and published in 1970 by Niklaus Wirth as a small and efficient language intended to encourage good programming practices using structured programming and data structuring.A derivative known as Object Pascal...

,
and share a common threaded code interpreter. The following describes how Concurrent Pascal differs from Wirth's Pascal.

Language Description

Several constructs in Pascal were removed from Concurrent Pascal for simplicity and security:
  • variant records
  • the goto
    Goto
    goto is a statement found in many computer programming languages. It is a combination of the English words go and to. It performs a one-way transfer of control to another line of code; in contrast a function call normally returns control...

     statement (and labels)
  • procedures as parameter
    Subroutine
    In computer science, a subroutine is a portion of code within a larger program that performs a specific task and is relatively independent of the remaining code....

    s
  • packed arrays
  • pointer types
  • file types (and associated standard input/output procedures).


These omissions make it possible to guarantee, by a combination of compile-time checks and minimal run-time checking in the threaded-code interpreter, that a program can not damage itself or another program by addressing outside its allotted space.

Concurrent Pascal includes class, monitor, and process data types. Instances of these types are declared as variables, and initialized in an init
Init
init is a program for Unix-based computer operating systems that spawns all other processes. It runs as a daemon and typically has PID 1. The boot loader starts the kernel and the kernel starts init...

statement.

Classes and monitors are similar: both package private variables and procedures with public procedures (called procedure
entries). A class instance can be used by only one process, whereas a monitor instance may be shared by processes. Monitors provide the only mechanism for interprocess communication in a Concurrent Pascal program.

Only one process can execute within a given monitor instance at a time. A built in data type, the queue, together with operations
delay and continue, are used for scheduling within monitors. Each variable of type queue can hold a single process; if many processes are to be delayed in a monitor, multiple queue variables, usually organized as an array, must be provided. The single process queue variable gives a monitor complete control over medium-term scheduling, but the programmer is responsible for unblocking the correct process.

A process, like a class or monitor, has local variables, procedures,
and an initial statement, but has no procedure entries.
The initial statement ordinarily executes forever,
calling local procedures, class procedures,
and monitor procedures.
Processes communicate through monitor procedures.
Language rules prevent deadlock by imposing a hierarchy on monitors.
But nothing can prevent a monitor from erroneously
forgetting to unblock a delayed process (by not calling continue)
so the system can still effectively hang up through programming errors.

The configuration of processes, monitors, and classes in a Concurrent
Pascal program is normally established at the start of execution,
and is not changed thereafter.
The communication paths between these components are established
by variables passed in the init statements, since class and
monitor instance variables cannot be used as procedure parameters.

Example

The following example shows the declaration of a simple monitor,
and its use by two communicating processes.

type
buffer =
monitor "bounded buffer monitor"
var
saved: integer; "saved item is an integer"
fullq, emptyq: queue; "used by only two processes"
full: boolean; "true if an item is saved:"
procedure entry put (item: integer); "puts item in buffer"
begin
if full
then delay(fullq); "block if full"
saved := item; "save the item"
full := true; "mark as full"
continue(emptyq) "unblock consumer"
end;
procedure entry get(var item: integer); "gets item from the buffer"
begin
if not full
then delay(emptyq); "block if empty"
item := saved; "get the item"
full := false; "mark as not full"
continue(fullq) "unblock producer"
end;
begin "initialize the monitor"
full := false
end;

producer =
process(pass: buffer); "producer uses a buffer"
var item: integer;
begin
cycle "execute in a loop forever"
"produce an item"
pass.put(item) "pass an item to the monitor"
end
end;

consumer =
process(pass: buffer); "consumer uses a buffer"
var item: integer;
begin
cycle
pass.get(item); "get an item from the monitor"
"consume the item"
end
end;

"declare instances of the monitor, producer, and consumer"
"give the producer and consumer access to the monitor"
var
pass: buffer;
prod: producer;
cons: consumer;
begin
init pass, "initialize the monitor"
prod(pass), "start the producer process"
cons(pass) "start the consumer process"
end.
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK