shmarr2.pll
来自「一个嵌入式系统的C代码」· PLL 代码 · 共 55 行
PLL
55 行
PROGRAM myshm (INPUT, OUTPUT);
{-----------------------------------------------------------}
{ PURPOSE: Simple Shared memory example }
{ Binary sem1aphore used to syncrhonize access }
{ }
{ AUTHOR: David Jones }
{ DATE: 18-APR-94 }
{-----------------------------------------------------------}
VAR
count, mysemA, mysemB, myshm, value, result, temp : INTEGER;
BEGIN
mysemA := SYSTEM(SEM_OPEN, 'sem1');
IF mysemA > 0 THEN
BEGIN
{ wait for other process to signal it's }
{ placed a value in the shared memory }
mysemB := SYSTEM(SEM_OPEN, 'sem2');
Writeln( 'I am now waiting for a signal from other process ' );
temp := SYSTEM( SEM_WAIT, mysemB );
myshm := SYSTEM(SHR_OPEN, 'myshm' );
IF myshm > 0 THEN
BEGIN
FOR count := 1 TO 10 DO
BEGIN
{ Get Value from shared memory }
value := SYSTEM(SHR_READ, myshm, count-1 );
Write( 'I read ', value# );
WriteLn( ' from shared memory, squaring it..' );
result := value * value;
temp := SYSTEM(SHR_WRITE, myshm, count-1, result )
END;
{ tell other process I've squared the value }
temp := SYSTEM(SEM_SIGNAL, mysemA );
temp := SYSTEM(SEM_CLOSE, mysemA);
temp := SYSTEM(SEM_CLOSE, mysemB);
temp := SYSTEM(SHR_CLOSE, myshm)
END
ELSE
BEGIN
Writeln( 'ERROR: You must execute shmarr1 before this program.' )
END
END
END.
{------------------------------ EOF -----------------------------}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?