• Aucun résultat trouvé

Figure 2.8. A sequence diagram

Dans le document [ Team LiB ] (Page 74-78)

In a programming language, the same transfer might be represented as:

myAccount.debit (100.0);

yourAccount.credit (100.0);

which would be a set of instructions in a method belonging to the object aTransfer.

[ Team LiB ]

[ Team LiB ]

2.3 The process concept

The style of modular specification outlined above gives a description of the components of a system and gives the intuition that the components interact as the system executes dynamically. We know that methods are invoked on objects and that the object's set of methods defines its possible behaviour. In Figure 2.3 we saw a thread of control pass from the object containing method A to the object containing method B and back, then to the object containing method C and back, when methods were invoked. We now focus on the dynamic execution of a system: the events that cause method invocations and the order in which invocations take place.

As well as an object model, a computational model is therefore required with a notion of active elements or activities which may call interface procedures or invoke methods on objects in order to carry out a computation. Active elements have been given a variety of names in systems: activities, processes, tasks or threads. We shall use the classical term 'process' for an abstract entity which executes a program on a processor; but see Section 2.3.2 for further discussion of multi-threaded processes.

A process must follow a protocol in order to use an object correctly, that is, a set of rules which define the order in which the object's interface operations may meaningfully be invoked. For example, a protocol for an existing file object is likely to be that the file is opened, a succession of reads and writes are then allowed, after which it is closed. If the protocol is not followed the invoker of the object may be given an error return, such as 'incorrect argument' if a file's pathname is given where an open file identifier is expected. In the case of a stack object an error might be 'attempt to pop from an empty stack' if pop is invoked before push.

Again, the point should be made that the syntactic specification of the interface of an object is necessary for correct use of the object but is not sufficient, in itself, to convey the meaning (or semantics) of the object's functionality. In the case of the file object, we require that the bytes we read from it are the same bytes that we previously wrote to it. The specification of a protocol is another means by which some of the intended semantics of the object is conveyed.

2.3.1 Process by analogy

To introduce the notion of process let us consider some analogies and see how far each can be taken:

The text of a book is comparable with the text of a computer program or the specification of a module. The activity of reading a book is comparable with the execution of a program by a process.

Two musicians sharing a score while playing a piece of music are comparable with two processes executing the same program on two processors simultaneously. Luckily, they need to turn the pages at the same time as they are playing synchronously.

I start to read a book, make a note of where I have got to and then put it down. My son picks it up, decides it looks interesting and starts to read. Over a period of time the two of us cooperate (or compete) over reading the book. This is again comparable to two processes executing a program. Since only one of us is reading at one time the analogy is with a program that for some reason may only be executed by one process at a time. In the case of the book, we can buy another copy to avoid sharing it.

I am reading a book; the phone rings; I answer the phone and go back to the book. This is comparable with a processor temporarily leaving the execution of a program to deal with an event such as a disk controller signalling that it needs attention after completing the transfer of some data.

In all cases there are the concepts of the static text and the dynamic process of reading it, which are analogues of the static text (code) of a program and the dynamic process of executing that code.

To put these ideas on a more concrete footing, here are some slightly more formal definitions, taken from Brinch Hansen (1973a):

data Physical phenomena chosen by convention to represent certain aspects of our conceptual and real world. The

meanings we assign to data are called information. Data is used to transmit and store information and to derive new information by manipulating the data according to formal rules.

operation A rule for deriving a finite set of data (output) from another finite set (input). Once initiated, the operation is completed within a finite time.

computation A finite set of operations applied to a finite set of data in an attempt to solve a problem. If it solves the problem it is called an algorithm, but a computation may be meaningless.

program A description of a computation in a formal language.

computer A physical system capable of carrying out computations by interpreting programs.

virtual machine

A computer simulated partly by program.

process A computation in which the operations are carried out strictly one at a time: concurrent processes overlap in time.

They are disjoint if each refers to private data only and interacting if they refer to common data.

In the case of software, the program text specifies objects' methods and they are executed dynamically by processes on one or more processors. A process may move from object to object by calling interface methods (see Figure 2.9).

Figure 2.9. (a) A process invoking a method.(b) A process executing code from methods belonging to several objects.

A given object may be used by a number of processes simultaneously. In a time-sharing system, for example, users may share a single copy of system utilities, such as editors or compilers. Each user has an associated process fetching and executing the instructions of the

shared code. Figure 2.10 shows two processes executing a compiler. Here the processes are shown as cyclic, since they are likely to spend time executing a loop such as 'fetch the next statement and translate it'. There must be different input, output and data areas for the two separate compilations.

Dans le document [ Team LiB ] (Page 74-78)