IBM AS/400 manual How to, Across, Share Data

Models: AS/400

1 489
Download 489 pages 47.95 Kb
Page 182
Image 182

Multithreading

Considerations

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

THREAD(*SERIALIZE)

will

protect

 

most

 

of your variables and all your intern

control

 

structures from being accessed improperly

by

multiple

threads.

safe module will be locked when

 

a

procedure

in

the

module is

entere

unlocked

when no procedure in the

module

 

is

still

running.

This

serializ

ensures

that

only

one

thread

is

active

in

any one

module,

within

an

a

group,

 

at any one time. However,

it

is

still

up

to

 

the

programmer

to

safety

for storage that is shared

across

modules.

 

This

 

is

done

by

the application to synchronize access to the storage. For example, sha

exported

and

imported

storage,

and storage accessed by the addres

eter

may

be

shared

across

modules

 

from

multiple

threads.

To

synchroni

to

 

this type

of

storage,

you

can

do

one

or

both

 

of

the

following:

¹

Structure the application such that the shared resources are not a

 

 

simultaneously

from

multiple

 

threads.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

¹

If

you are going to access resources simultaneously from separate

 

 

synchronize access using facilities such as semaphores or mutexes.

 

 

information, refer to the Multithreaded Applications document

 

under

th

 

 

gramming topic at the following URL:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

http://www.as400.ibm.com/infocenter/

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

How to

Share Data

 

Across

More

 

Than

 

One

Module

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Serializing access to modules using the THREAD(*SERIALIZE) control

 

specific

keyword

ensures sequential access

to

global

data

within

each

 

module,

not ensure sequential access to

shared data across modules. It is

grammer

 

to ensure that only one

thread can access shared data

at

o

Two

or

 

more

modules

can

access

the

 

same

data

if:

 

 

 

 

 

 

 

 

¹

EXPORT/IMPORT

keywords

are

used

on

 

the

 

definition

specifications

 

 

¹

Files

 

are shared

across

modules

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

¹

Data

 

is based on a pointer

where

the

pointer

is

available

to

more

 

 

module

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

For

example,

procedure

A

in

 

module

A

passes

a

pointer to

procedure

B

B,

 

and

procedure

B

saves

the

pointer

in

a

static

 

variable.

 

Now

both

access

to

the

based

storage

at the same time as the thread runnin

accessing the storage. Once procedure B returns, another thread coul

cedure

in module B and access

the based storage. Serialization of

storage

within modules A and B

would not prevent simultaneous access

of

same storage in each module. The following is an

example

of

two

module

access

the

same

data.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

158 ILE RPG for AS/400 Programmer's Guide

Page 182
Image 182
IBM AS/400 manual How to, Across, Share Data