
B–61863E–1/06
D. EXAMPLES OF PROGRAMSAPPENDIX
493
D This program uses the semaphor to stop execution of TASK-1 from
TASK-2.
D TASK-1 acquires and releases the semaphor while turning K10.0 on and
off.
D TASK-2 uses an event (X1000.0 on) to acquire the semaphor.
D This causes TASK-1 to enter a wait state for the semaphor and K10.0
stops turning on and off.
TASK-1
Wait SEM
K10.0 ON/OFF
Signal SEM
SEM
(STOP) X1000.0 ON
Wait SEM
(START) X1000.0 OFF
Signal SEM
TASK-2
/*==============================================================*/
/* sema man task–1*/
/*==============================================================*/
#include <pmclib.h>
#define K0000 3408
#define Kbit(a,b) ((a+K0000)*8+b)
long tim ;
void far test_tsk1()
{
tim = 10 ;
os_mak2_sem(10,0,0) ;
for( ; ; ){
os_wait_tim(tim) ;
os_wait_sem(10,(long)0) ;
pl_membwrt(Kbit(10,0),pl_membrd(Kbit(10,0))?0:1);
os_sign_sem(10) ;
}
}
/*==============================================================*/
/* sema man task–2*/
/*==============================================================*/
#include <pmclib.h>
#define X1000 1600
#define X1000bit(a,b) ((a+X1000)*8+b)
long tim ;
void far test_tsk2()
{
for( ; ; ){
for( ; !pl_membrd(X1000bit(0,0)) ; ) ;
os_wait_sem(10,(long)0) ;
for( ; pl_membrd(X1000bit(0,0)) ; ) ;
os_sign_sem(10) ;
}
}
D.3
SEMAPHOR
MANAGEMENT
FUNCTION