⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 initval.c

📁 这是unix网络编程一书的源代码希望能对大家的学习提供一种便利
💻 C
字号:
#include	"unpipc.h"

#define	NSEMS	10		/* #semaphores in set */

int
main(int argc, char **argv)
{
	int		semid, i, j;
	unsigned short	*ptr;
	union semun	arg;

		/* 4allocate memory to hold all the values in the set */
	ptr = Calloc(NSEMS, sizeof(unsigned short));
	arg.array = ptr;

	for (j = 0; j < 1000; j++) {
			/* 4create a semaphore set */
		semid = Semget(100, NSEMS, IPC_CREAT | IPC_EXCL | SVSEM_MODE);

			/* 4fetch the "initial" values and print */
		Semctl(semid, 0, GETALL, arg);
		for (i = 0; i < NSEMS; i++)
			printf("semval[%d] = %d\n", i, ptr[i]);

			/* 4store new values for entire set */
		for (i = 0; i < NSEMS; i++)
			ptr[i] = rand();
		Semctl(semid, 0, SETALL, arg);

			/* 4and delete the set */
		Semctl(semid, 0, IPC_RMID);
	}

	exit(0);
}

⌨️ 快捷键说明

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