📄 tsk2.c
字号:
/* tsk2.c - Task #2 */#include <psos.h>#include <prepc.h>#include <stdio.h>#include "misc.h"#include "appl.h"/* wait_for_semaphore() - Wait until a semaphore exists */ULONGwait_for_semaphore(char name[4], int maxwait){ ULONG rc, smid; int try = 0; do { /* See if the semaphore exists */ if (0 == (rc = sm_ident(name, 0, &smid))) return(smid); /* YES, SUCCESS! */ /* No semaphore yet. Wait a while and try again */ tm_wkafter(10); } while (try++ < maxwait); /* Try this many times */ fail(rc, "wait_for_semaphore: timed out waiting for %s", name); /* The "successful" return is above, in case you missed it. */}void tsk2(ULONG me, ULONG him, ULONG l3, ULONG l4){ ULONG smid, rc; int tally = 0; bprintf("\t\t\t%s Task begin\n", (char *) me); smid = wait_for_semaphore(SEM_NAM, 100); for (;;) { rc = sm_p(smid, SM_WAIT, 0); if ((rc == ERR_OBJDEL) || (rc == ERR_SKILLD)) break; /* Semaphore has been deleted. Break loop and delete self. */ else if (rc != 0) fail(rc, "%s sm_p(%08x) failed", me, smid); tally++; bprintf("\t\t\t%s awakened, tally is now %d\n", (char *) me, tally); } bprintf("\t\t\t%s Task end\n", (char *) me); exit(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -