An algorithm for the diagnosis of deadlocks

An algorithm for the diagnosis of deadlocks

AN ALGORITHM FOR THE DIAGNOSISOF DEADLOCKS* V. S.AROLOVICH and V.M.MIKHELEV (Received 6 January 19721 THIS paper is devoted to the analysis of dead...

706KB Sizes 4 Downloads 99 Views

AN ALGORITHM FOR THE DIAGNOSISOF DEADLOCKS* V. S.AROLOVICH and V.M.MIKHELEV (Received

6 January

19721

THIS paper is devoted to the analysis of deadlocks, that is, situations some of the problems being solved by a computer in the multiprogramme cannot

continue

their solution

on account

of interdependencies.

in which mode,

It is proved

that if the dependencies of the problem are represented by a system of equations and their left sides are multiplied, the problems forming a deadlock can be determined from the form of the product obtained. In terms of the matrices constructed possible

from this system of equations, an algorithm is formulated, making to find the minimal sets of problems whose completion by special

of exclusion from the number to be solved removes The discussion is illustrated by examples. In the solution locks may occur; cessed

cannot

other problems

of problems these

on a computer

are situations

be solved or because

the deadlock

from the system.

in the multi-programme

where some of the problems

further because of the absence

of the expectation of the necessary

it means

mode deadbeing

of signals

pro-

from

resources.

In II-31

algorithms were given which for some conditions enable deadlocks to be predicted, and if these conditions are not satisfied they enable the set of problems causing the deadlock to be indicated. In this paper we consider

an algorithm

situations,

where the connections

by Boolean

functions

between

or in an equivalent

for the diagnosis the problems mathematical

of deadlock

are described form.

explicitly

Such an explicit

description enables the solution of the problem to be simplified, requiring a more detailed analysis of the connections, such as a search for the minimal subset of problems which, because of the inclusion of special alarm devices of the operational system or their exclusion, leads to the resolution of the deadlocked situation, and also to an explanation of the deficient resource and the possibility *Zh.

uychisl.

of replacing

Mat. mat. Fiz.,

it.

12. 6, 1543-1553,

213

1972.

V. S. Arolovich

214 We consider

the set of problems

and V.

2 = IT,,

programme mode.

As was shown in Ill,

may be suspended

because

expectation

of explicit

of resources)

M. Mikheleu . . . , Tk! being solved of some of these

(the expectation

of signals)

dependencies

resource

because

R occupied

be continued possibility

of the fact that,

by problems

T,,

only after obtaining of continuing

explicit

and latent,

no direct

effect

T,

firstly,

and T,,

some signal

(the

and secondly,

on whether

where the dependence

and that on T, and T,

of problem T,

it requires

is latent

units of some its solution

from problem T,.

problem T, depends

T,, T, and T, can be continued,

problems

or latent

on other problems.

Example 1. Let Z = {T,, T,, T,, T,, T, 1 and the solution have been suspended

in the multi-

the solution

the solution on problem

only;

can

Then the of problems

T, is both

problem T, exerts

on T,.

The cortege

(Tall

. . . , TaN) of problems of the set Z is called

a

basic

string if for each problem To, 1 ,( l< N, one of the following two conditions is is solved; (2) the completion of some problems satisfied: (1) problem T T a: ., l,(

TaJ (it is considered an (f has emitted

available

conditions

that the completed

1 suppose

Considering

of problem

problem has released

all the problems

only 2 free units;

problems

respectively.

of problems

for the continuation

all its resources

to the other problems).

for 5 units of the resource

resource,

solution

sufficient

all signals

In example T, is waiting of this

O’l

j < 1, creates

are being solved

except

R, and the operative T,,

T, and T,

The deficient

occupy

system

has

2, 1, and 4 units

3 units will be released

T, and T1, or alternatively

T1, where

if the

that of problem T, , is completed.

also the explicit

dependence of T, on T,, we obtain that T, may T, and TB, or T, and T, are completed. Then the basic strings are, for example, (T,), (T,), (T,, T,), (T, , TJ, CT,, T,, T,>, CT,, T,, T,). The strings (T,), (T,, T,), (T,, T,), (T,, T,, T,, T,) etc. are not basic. be continued

if problems

ItiseasytoseethatifC,=(T,r,...,T basic

strings,

also.

This

)andC,=(Tp,...,T

then C,C, = (Tar, . . . , T,

statement

is extended

, Tppi” . . ,

T

PM

)

1 is a basic

in an Obvious way to a greater

PM

>are

string

number of

strings. We introduce to construct

the Boolean

a basic

But if it is not possible

hi = 0.

function

string (Tat,

hi =

. . , , T,

to construct

a bkic

h(Ti) on the set 2.

If it is possible

= Ti) for problem Ti, we put hi = 1. string

for problem Ti we put

An algorithm for the diagnosis We call the function possibility Ti.

h the

expectation

(hi = 1) or impossibility

The recognition

zero expectation It is easy

Its value expresses

function.

(hi = 0) of continuing

of a deadlock

reduces

215

of deadlocks

the solution

the

of problem

to finding a set of problems

with

function. to see that in example

1 all the expectation

functions

are equal

to unity. We introduce

the variable

with each problem Ti whose a Boolean

disjunctive

Boolean

vector

solution

is suspended

a

normal form of the variables p(i) F,(x)=

(1)

where for each fixed

dependence function Fi -

x1,

v

. . . , ~i_~,

Xi+l,

. . . , xk:

A

XVzmn

?

n=*

m, 15 m< p(z], the completion

q(i, m), creates

. . . , xk) and associate

q(i, n2)

m=i

n= 1, ,..,

x = (x,,

sufficient

conditions

of the problems

for the continuation

Tyimn, of problem

Ti. In example

1 for problem T, we have

F,(x) = x,x, We introduce place

the vector

of the corresponding

that hi = 1 implies

h = (h,,

. . . , hk).

components

If we substitute

of the vector

Fi(h) = 1. Indeed, Fj(h) ZmVn

consequently,

‘v’ x,x,.

&,,,,,,=

= 1 means that 1,

for every problem Tyimn we can construct

It is easy to see that

c

.c ‘iml

is a basic

string,

so that hi = 1.

*’

Yim*(i,m)

Therefore,

holds.

(Ti)

the relation

Vi(h)

+

hi) = 1,

‘i(h)

V

hi = 1.

or (2)

its components

x in (1), it is easy to see

the basic

string

Hymn.

in

V. S. Arolovich

216

and V. M. Mikhelev

We now construct the following system of k equations.

If problem Ti is

solved, the i-th equation of the system is of the form Xi = 1. But if the solution of problem T, is suspended, the i-th equation of the system is of the form

We call the set of equation obtained in this way the ~~~~~~~~s~~~ systen. It is easy to see that the vector h is the solution of this system. if problem T, is solved, a basic string (Z’$ exists

for it and hi = l.But if the

solution of problem Ti is suspended, we take the expression substitute

(1) for F, and

it in (21

This reiation can be transformed into the equivalent

Therefore,

Indeed,

form

all the equations of the system are satisfied.

For example 1 the characteristic

system is of the form

We show that the characteristic system permits the set of problems leading to a deadlock to be found without having recourse to basic strings. We first notice that each i-th equation of the characteristic system of the form (3) can be written in the equivalent

form

An algorithm

for the diagnosis

217

of deadlocks

Lemma 1 If (Tal, . . . , T equations

) is a basic *N

of the characteristic

form xa, . . . X,

system

hence

to it.

Let

>. Consider

statement

for the problem of this string

with respect

in the characteristic

T

O[N-*

the product of the left sides

khe statement

system

to N.

For N = 1 problem

the equation

X,

for problem T,. remains T,

of some problems

for the continuation

of problem

T

products

variables

string (T,

valid.

Therefore

of the system

easy to see that the term

N

= 1, the

is of the

of a basic

string,

sufficient

in (1) at least

to only problems

left side by the product xa, . . . X,

, ...,

But if this equation

, 1~ I< N must create

“N’

corresponding

For the aN-th equation

I

TaI is

If it is of the form x,’

form (3), where i = aN, it may be noted that by the definition

contains

are of the

= 1 corresponds

of the lemma be true for the basid

the equation

of the lemma obviously

the completion

of the

.

N

The proof is by induction solved,

string,

conditions

one of the

of the string

(Tal,

. . . , ‘I’,

we now use the form (4) and multiply obtained

N-I

by the inductive

N-I

the

hypothesis.

It is

p(i) s(i,m)

is cancelled

A

A

ml,

7l-i

and only the product xix,

The product of the left sides system,

xvimn J-k,. * * xa_v_,

represented

1

. . .x

aN_1

E x

of all the equations

in disjunctive

remains. OL1’” xa ,PJ of the characteristic

normal form, is called

the

characteristic

product. Theorem 1 If xi occurs We assume exists,

in

in the characteristic

the contrary:

product,

hj = 1. Then a basic

and by Lemma 1, the product of the left sides

characteristic

xa

inversely

xi.

system

We multiply

271. isjunctive

for the problems the remaining

normal form.

of this string

left sides

If then not a single

hi = 0.

string (‘I’,,

, . . . , T, = Ti)

of the equations

of the

are of the form x

...

and represent

their product Prem

term in Prem contains

< as a

).

V. S. Arolovich

218

factor,

3ciwill

contains

not occur

and V. M. Mikhelev

in the characteristic

xi, it is cancelled

product either.

on multiplication

there remain only the term not containing

But if some term

by x,+ . . . Xi, so that in this case

zi, which contradicts

the hypothesis

of the theorem.

Corollary It is possible

to take xi out of the brackets

of the characteristic

equation

if and only if hi = 1. Indeed,

if hi = 1, we have

. ..x aN_l P rem’

P(x)=xixa 1

where P(x)

is the characteristic

the terms,

we have hi = 1, since

Indeed,

the definition

of the system, have P(h)

On the other hand, if xi occurs

product.

hi = 0 implies,

of the characteristic

we have P(x)

= 1;

product implies

in particular,

in all

= 0, but this is impossible.

P(h) since

that if x is a solution

h is a solution,

we also

= 1.

Therefore, characteristic

it is sufficient system,

all the expectation

to multiply

the left sides

of the equations

in order to find from the form of the characteristic

functions

and thereby

determine

which problems

of the product

become

deadlocked.

Example 2.

Let the characteristic

system

be of the form

(52 v X1) (5% v fa v 51) = 1, E, v x2 = 1, x3 = 1, zzv5%vx&=

1,

(ZFui v X5) (2, v 55) = 1. After multiplying

the left sides,

--

-

P(x) =x,x,x,x,x, From this we conclude T,, T,,

we obtain

\/x,x,x,x,xs =X&l

---

(X1X&

VW&,).

that h, = h, = h, = 0, h, = h, = 1, that is, the problems

T,-

We denote

by E the set of problems

whose expectation

function

equals

unity,

An algorithm

2’

= Z\E

for the diagnosis

is the set of problems

We call equations

with zero expectation

the set of problems

S G Z’

of the characteristic

system

of the form Xi = 1 the characteristic corollary

this is equivalent

219

of deadlocks

a resolving

function.

set,

for the problems

product acquires

to all the expectation

if on replacing

the

of the set S by equations

the form X, . . . xk (by the

functions

becoming

equal to

unity). We call a resolving subset

set of problems

of it is a resolving

It is easy to verify resolving

sets,

not minimally

T,!, {T,,

system

a deadlocked if hi = 0, since

equations

hence

2 the sets

(!I’,], IT,!,

lT,I

are minimally

IT,, T,], IT,, T,, T,] are resolving

It is easy functions Conversely,

are suspended

equations

but

of the system

functions

is deadlocked

are equal

it cannot

to construct

to zero.

contain

if there are no equations

and it is impossible

all the expectation

of the form xi = 1 will

to see that a system

of all the problems

h is the solution

of the form Xi = 1.

all the problems string,

T,],

not containing

system.

if and only if the expectation Indeed,

set if no proper

resolving

resolving.

A characteristic be called

that in example

and IT,,

a minimally

set.

of this form,

a single

basic

are zero.

Lemma 2 Let a deadlocked

system

be given and S be a resolving

system

there is an equation

in the left side of which at least

inverse

terms corresponding

only to problems

If S = Z (since 2’

the system

= Z), and the statement

U = Z\ S is not empty.

is deadlocked,

p(i) il(i,jJl) _ /j ( V Xyimn V

Tid

m=l

xi)

It has to be proved that

We assume

Let S c

that this is untrue,

that is,

A Tj”S

n=,

3iarnvn

one factor

in the contains

we have h = 0, consequently

of the lemma is trivial.

/j

Then

of the set S.

We put

P’ E

set.

l’, ,,,,,E S.

x+

2.

Then the set

220

V. S. Arolovich

Then,

P’ in disjunctive

representing

terms

normal form, we obtain

A xv imn(i,m)

TidJ

term is not cancelled,

A

m=i

since

of U, and the non-inverse

contradiction

all the inverse

ones to problems

proves

the equation

element

Yimn

be given,

set

not necessarily

deadlocked.

are of the form (3),

since

between

the characteristic

system

the i-th submatrix.

Each

m-th row of

with the Yimn-th column the

. . . . q(i, m), with the i-th column the element

the remaining

elements

the characteristic

and the

TO each problem Ti in this matrix there corres-

at the intersection

way is called

For example

to problems

of (3) for p(z) = 1, q(i, 1) = 0 (the sum

in the aggregate

contains

,n=l,

x

case

a correspondence

pond p(z) rows, called

correspond

to be equal to zero).

matrix of k columns.

the i-th submatrix

of a resolving

that all its equations

xi = 1 is a particular

We establish following

system

we will assume

of 0 terms is considered

factors

of S.

the lemma.

Now let some characteristic For generality

xj*

Tj”S

On the other hand, from the definition

This

as one of the

p(i) A

This

and V. M. Mikhelev

The matrix constructed

of the row are zeros.

matrix.

2 the characteristic

matrix is of the form

0 0 0 z4 0 Xl 0 .?3 . . . . . . . . . Xl

g2

Zl

x2

0

d

. 0.

. 23.

.

.0 .

.0

(j

‘j;:,‘

0.

.

.

.

.

.

.

.

.

0

0

x3 . 21 0

.

. 0 0

.

.

25

0

0

25

z3

0

55

xi.

All

in this

An algorithm

(the submatrices

are separated

We call the i-th cross obtained

for the diagnosis by dotted lines).

of the characteristic

by the union of the i-th submatrix

We now formulate (1)

an algorithm

all the crosses

are deleted.

221

of deadlocks

matrix the set of elements

and the i-th column.

which generates

a set of problems

in which rows occur not containing

If new rows without inverse

elements

inverse

have appeared,

X c

Z:

elements, then to para-

graph 1). (2)

if the matrix is not exhausted,

(3)

crosses

an arbitrary

row is selected,

otherwise,

end;

of the chosen set X;

with subscripts

row are deleted;

to paragraph

(Explanation:

equal to the subscripts the corresponding

of the inverse

problems

elements

are included

in the

1). after the deletion

of crosses

the submatrices

and columns

are

not renumbered.) We notice

that the deletion

of the i-th equation

value

Xi = 1 in the remaining

may be regarded

of the i-th cross

from the characteristic equations.

as a characteristic

of problem

Ti is carried

number of problems

to be solved:

solution

is a row in the submatrix that is, the corresponding is taken outside hi = 1. as usual. becomes

Hence

deadlocked,

which implies,

to the crosses

(2) is E, and paragraph

deleted

outside

before

(2) and paragraph

of the set Z’ , so that in paragraph in a deadlock

indicates

the completion

in the elimination

Hence

of the corresponding

from the number of problems of those

problems

inverse

l), there elements, Then xi

and by the corollary, and can be solved

(2) the system

obviously

that the set of problems

the first

application

of paragraph

(3) are applied to the system

problems

are deleted.

the deadlock

in particular,

of the

in paragraph

product,

if the

from the

xi on the left side.

(1) to paragraph

problems

their elimination

is deleted

which does not contain

has the factor

from paragraph

in this way

all the dependencies

of the characteristic

problem Ti is situated

On passing

corresponding

equation

the brackets

case

of the

which arises

or it is eliminated

If a cross

of this cross

transformed

for the situation

to completion in either

to the elimination

and the substitution

The system

system

on Ti are cancelled.

other problems

is equivalent

system

(3) the crosses the deletion problems

from the set X.

corresponding

of these by special

to be solved,

for to

crosses means or

which is reflected

222

V. S. Arolovich

It is obvious

from the above that by means

by one more method which problems this by example

and V. M. Mikhelev

2.

In the characteristic

on the completion

of paragraph

of paragraph

have become

deadlocked.

(1) we can determine We will consider

matrix there is the row 00x,00,

(1) the third cross

is deleted,

therefore

after which the

matrix becomes 21

a2

0

0

21

0

54

0

. . . . . . . . 51

0

52

0

. . . . . . . . 0

22

54

%

. . . . . . . .

Since the row 000x, cross

is deleted.

$1

0

0

21

0

0

0

xt

has appeared,

There

remains

paragraph

(1) is executed

again;

the 5-th

the matrix Xl

372

0

0 34 Xl . . . . . . Zl

x2

0'

. . . . . . _ 0

in which there are no longer lock is formed by problems obtained

52

541

rows of the required

form.

Consequently,

the dead-

T,, T, and T,, which is the same as the result

previously.

Theorem 2 The set X generated

by the algorithm

It is easy to see that X c

described

is a resolving

set.

2’ .

We denote by Yl the set of problems corresponding to the crosses deleted at the I-th application of paragraph (1). We replace all the equations for the problems of the set X by equations of the form xi = 1 and show that in the modified system the product of the left sides of the equations for the problems of the set

Z[=

U YjUX j
An algorithm

is equal to

for the diagnosis

of deadlocks

223

A Xi. =1 EZL

The proof is by induction

with respect

are of the form xi = 1 from the definition same form by the construction sides

we obtain

A Xi. TiEZl

form

inverse

After multiplying

In the general

elements

case

Ti E Y,

of Y, that for every problem

there is a row containing corresponding

of the new system.

the required

from the definition

1. For 1 = 1 the equations

to

for Y,

of the set Y,, and for X they are of the the left

it is easy to see

in the i-th submatrix

only at intersections

with columns

to the set

Yj U X = Zl-i.

U kr This

means that in each of the corresponding

factors

of the left side contains

inverse

of the set Z,_, . After representing form (4) and multiplying

equations

of (3) one of the

terms corresponding

the left sides

by the product

A

only to problems

of all these

equations

obtained

xi,

in the

by the inductive

TiC-Zl-1

hypothesis,

we obtain

To complete

the required

the proof of the theorem

fact that if in the operation thenZL

1

A

Ti=Zl

Xi* it is sufficient

of the algorithm

paragraph

to notice

the obvious

(1) is applied

L, times,

=Z.

We continue If in paragraph

the discussion (2) we select

and problem ‘I’, is recorded

of the operation

as an element

Xl * 0

If the row x,0x,

of the set X.

the matrix

x4

of paragraph

the fourth cross

$2

0 . . .

Xl

21

We obtain

2.

is deleted

*

of problem !I’,, and the matrix Xl

on example

cross

54 .

after a twofold application is selected,

the second

0

Xl

which is exhausted

of the algorithm

the row x,xzO or O&4,

22

7

is deleted,

(1). with the recording

V. S. Arolovich

224

arises,

which is also completely

Finally,

on selecting

and V. M. Mikhelev

deleted

on account

the row ,x,0,

we delete

of paragraph the first cross,

(1). record problem

T, in the set X and obtain the matrix 0

X2

*.. 22

which is also exhausted

, II

on the operation

of paragraph

(I).

Therefore, by selecting different rows in paragraph (2) of the algorithm described, different resolving sets can be obtained. In this example we obtained as such sets (T,i, (T,\, {T,!. It can be seen by this example that the algorithm does not give all the resolving sets: thus, the set ET,, T,, T,f, obviously a resolving set, is not obtained for any choice of the rows in paragraph (2). However, those resolving sets which are of greatest practical interest, namely the minimally resolving sets, are completely included in the algorithm. This follows directly from the following theorem.

Theorem 3 If S is a resolving

set, the rows in paragraph

(2) can be so selected

that

x E s. We denote paragraph (3); paragraph

by Xl the set of problems z’, is the set of problems

(2) is applied

S, is a resolving

include in X at the l-th application of corresponding to the system to which

at the I-th time;

sI = S fl 2,‘;

it is easy to see that

set for Z’,.

By Lemma 2, in the characteristic matrix of a deadlocked system there is always a row containing inverse elements corresponding only to problems of the resolving set. Hence if each time we select in paragraph (2) the m-th row of the i-th submatrix

by Lemma 2, then for each Z-th application Since

of para-

graph (3) we will have X1 or Si.

where L, is the number of applications theorem is proved. In particular,

if S is the minimally

of the rows in paragraph

of paragraph

resolving

(2) we can obtain

X = S.

(3), we have X z s.

set, for an appropriate

The

choice

An algorithm

The converse obtained

statement

by this

characteristic

for the diagnosis

is not true,

algorithm

is minimally

that

of deadlocks

225

is, not every

resolving.

set X which

For example,

can be

for the

system

1, 5, v x2= 1, f,Vf,Vx,=l 52 v xi =

the sets

IT’,\ and IT,\

will

be minimally

resolving,

while

if in the characteristic

matrix

on the

application

of paragraph

(2) we choose

the row x,x,x,,

the algorithm

X = IT,, T,I.

gives

The choice of a deadlock

of a particular may be carried

minimally out,

resolving

for example,

set

in the practical

by weighting

resolution

functions

on the set

2. Therefore,

if the algorithm

(2) are selected obtained, must

and each

of them

be performed

serves

in order

as the initial

structed free

in all possible

by starting about

problems

(the

The

vector

The

authors

the manuscript

to remove

about

repeatedly

and the Irows

all the minimally

resolving

which

problems

the deadlock.

for the algorithm. about and also

of the problem

The characteristic

matrix

matrix by some

explicit

resources type

system

particular

dependencies

V, W, A in the notation

for a given

may be con-

of the operative

occupied

of insufficient

if the request

will be operation

This

about

in paragraph sets

any particular

the resources

the resources

problems,

u and the matrices

algorithm,

as a fictitious

with

from information

expected

solution

by a similar

shows

information

for use by problems,

problem,

is applied ways,

between

of [l]).

may be obtained

of resource

is treated

problem. sincerely and made

thank a number

M. F?. Shura-Bura, of extremely

who carefully

useful

read

and important

Translated

through comments.

by J. Berry

REFERENCES 1.

AROLOVICH, V. S. and MIKHELEV, V. M. Some algorithms of the distribution of resources in the multiprogram solution of problems. Zh. uychisl. Mat. mat. Fiz., 12. 4, 1061-1066, 1972.

226

V. S. Arolovich

and V. M. Mikhelev

2.

HABERMANN, A. N. Prevention 373377, 385, 1969.

of system

deadlocks.

3.

SHOSHANI, A. and COFFMAN, E. G. Sequencing taks in multiprocess, Proc. 11-th Annual Symposium resource system to avoid deadlocks. and Automata Theory, 225-233, Oct. 1970.

Commune.

ACM,

12. 7,

multiple on Switching