IBM AS/400 manual Considerations, Deadlock Example

Models: AS/400

1 489
Download 489 pages 47.95 Kb
Page 184
Image 184

Multithreading

Considerations

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

complete their

calls,

since

each module will be locked by the thread

module. This type of problem

can

occur

even

with

serialization

of

cal

and is referred to as deadlock.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Figure

74.

Deadlock Example

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

This

example

shows

that

you

cannot access more than one procedure in

module

at

the

same

time

using

ILE RPG

synchronization

 

techniques.

 

To avoid

the

problem

in

the

above

example

and

ensure

thread

safe

a

you

can control the synchronization of modules using techniques

provided

by

platform functions. Any callers of PROC1 or PROC3 for each thread

the

following:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1. Restrict

access

to

the

modules

for

all

threads

 

except

the curr

in

the

same

order

(MOD1

then

MOD2)

 

 

 

 

 

 

 

 

 

 

 

 

 

2. In

the

current

thread,

call

the

procedures

in

the

modules

(PROC1

3. Relinquish

access

to

the

modules

for

all

threads

 

in

the

reverse

(MOD2

then

MOD1).

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

One

thread

would be

successful

in

restricting

access

to

MOD1.

Since

MOD1

and MOD2 use the protocol of restricting access

to

MOD1

and

MOD

order,

no

other

thread

can

call procedures in MOD1 or MOD2 while the

has

restricted

access

to the modules.

In

 

this

situation

you

have

a

than

one

procedure

in the

same

module

at

the

same

time,

but

since i

able

to the current thread, it is thread safe.

 

 

 

 

 

 

 

This

method

should

also

be

used

to

synchronize

access

to

shared

sto

160 ILE RPG for AS/400 Programmer's Guide

Page 184
Image 184
IBM AS/400 manual Considerations, Deadlock Example