TCE_Sem *sem,*wait;
|
...
|
void func1(p1)
|
{
-
...
-
tce_sem_down(sem); /* enter critical section */
-
... /* do some work */
-
tce_sem_up(sem); /* leave critical section */
-
tce_sem_down(wait); /* wait for parent to let me exit */
|
}
|
void func2(p2)
|
{ ...
-
tce_sem_down(sem);
-
... /* do some work */
-
tce_sem_up(sem);
-
tce_sem_down(wait);
|
}
|
void main(int argc, char *argv[])
|
{
-
TCE_Thrd *thrd1,*thrd2;
-
int prm1,prm2;
-
...
-
wait = tce_sem_init(0); /* create semaphore, set counter to 0 */
-
sem = tce_sem_init(1);
-
thrd1 = tce_thrd_init(func1,prm1);
-
tce_thrd_start(thrd1);
-
thrd2 = tce_thrd_init(func2,prm2);
-
tce_thrd_start(thrd2);
-
...
-
tce_sem_free(); /* let them proceed */
-
...
|
}
|