Texas Instruments TMS320C3x 사용자 설명서

다운로드
페이지 757
Interlocked Operations
7-17
Program Flow Control
Figure 7–2. Multiple TMS320C3xs Sharing Global Memory
Global memory
Arbitration logic
’C3x #2
XF0
XF1
Local
memory
Local
memory
’C3x #1
XF0
XF1
(X)A
(X)D
CTRL
(X)A
(X)D
CTRL
Lock, 
count
, or S
ADDR
CTRL
DA
T
A
Sometimes it may be necessary for several processors to access some
shared data or other common resources. The portion of code that must access
the shared data is called a critical section.
To ease the programming of critical sections, semaphores may be used.
Semaphores are variables that can take only nonnegative integer values. Two
primitive, indivisible operations are defined on semaphores (with S being a
semaphore):
V(S):
S + 1 
 S
P(S):
P:
if (S == 0), go to P
else S – 1 
 S
Indivisibility of V(S) and P(S) means that when these processes access and
modify the semaphore S; they are the only processes doing so.
To enter a critical section, a P operation is performed on a common semaphore,
say S (S is initialized to 1). The first processor performing P(S) will be able to enter
its critical section. All other processors are blocked because S has become 0.
After leaving its critical section, the processor performs a V(S), thus allowing
another processor to execute P(S) successfully.