shm1.pll
来自「一个嵌入式系统的C代码」· PLL 代码 · 共 46 行
PLL
46 行
PROGRAM Shm1 (INPUT, OUTPUT);
{-----------------------------------------------------------}
{ PURPOSE: Simple Shared memory example }
{ Binary semaphore used to syncrhonize access }
{ }
{ AUTHOR: David Jones }
{ DATE: 18-APR-94 }
{-----------------------------------------------------------}
VAR
sem, shm, value, result, temp : INTEGER;
BEGIN
{ create semaphore and make sure it is set to 0 }
sem := SYSTEM(SEM_CREATE, 'mysem', 0);
shm := SYSTEM(SHR_CREATE, 'myshm', 1);
IF (sem > 0) AND (shm > 0) THEN
BEGIN
Write('Enter a number ==> ' );
Read( value# );
Writeln( 'Value was read' );
temp := SYSTEM(SHR_WRITE, shm, 0, value);
{ Signal other process that it now has a value to work with }
temp := SYSTEM( SEM_SIGNAL, sem );
{ Wait for other process to read value }
{ from shared memory and square it }
Write('Waiting.. ');
temp := SYSTEM(SEM_WAIT, sem);
WriteLn; WriteLn;
result := SYSTEM(SHR_READ, shm, 0);
WriteLn( value#, ' squared is ', result# );
temp := SYSTEM(SEM_CLOSE, sem);
temp := SYSTEM(SHR_CLOSE, shm)
END;
END.
{------------------------------ EOF -----------------------------}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?