tsk1.c

来自「pSOSystem系统调用的例程」· C语言 代码 · 共 37 行

C
37
字号
/* tsk1.c - Task #1 */#include <psos.h>#include <prepc.h>#include <stdio.h>#include "misc.h"#include "appl.h"void tsk1(ULONG me, ULONG him, ULONG l3, ULONG l4){	ULONG	smid, rc;	int	loop_count, how_many, how_many2;	bprintf("%s Task begin\n", (char *) me);	if (0 != (rc = sm_create(SEM_NAM, 0, 0, & smid)))		fail(rc, "%s sm_create(%s) failed", me, SEM_NAM);	srand(123456781L);	for (loop_count = 0; loop_count < LOOP_MAX; loop_count++) {		tm_wkafter(DELAY);		how_many = how_many2 = rand() % 10;		while (how_many-- > 0)			if (0 != (rc = sm_v(smid)))				fail(rc, "%s sm_v(%s) failed", me, SEM_NAM);		bprintf("%s added %d credits\n", (char *) me, how_many2);	}	tm_wkafter(DELAY);	/* Allow tsk2 to get final credits */	if (0 != (rc = sm_delete(smid))) {		/* Ignore sm_delete()'s return code since we can't be		   sure if tsk2 will be on the sm_p() at that moment. */	}	bprintf("%s Task end\n", (char *) me);	exit(0);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?