示例#1
0
文件: feux.c 项目: borgaaydin/3TC
void quit() {
    printf("Feux : Je meurs.\n");
    down(id_mutex);
    pshmem[PID_FEUX] = 0;
    up(id_mutex);
    remove_shmem(id_shmem);
    exit(0);
}
void quit() {
    printf("generateurTrafficPrioritaire : Je meurs.\n");

		down(id_mutex);
		pshmem[SRC_PRIO] = 0;
		pshmem[DEST_PRIO] = 0;
		pshmem[ID_PRIO] = 0;
		pshmem[PID_PRIO] = 0;
		up(id_mutex);

    remove_shmem(id_shmem);
    exit(0);
}
示例#3
0
static void cleanup(void)
{
	remove_shmem();

	if (sock_fd >= 0) {
		if (*sock_path != ':')
			unlink(sock_path);
	}

	if (comm_fd >= 0)
		unlink(shm->comm_path);

	pthread_cancel(thread);
}
示例#4
0
int main()
{
	int key = 123 ;
	int memsize = sizeof(int) ;	
	
	int shmemId = create_shmem(key, memsize) ;
	if (shmemId == -1) {
		perror("shared segment creation error") ;
		exit(EXIT_FAILURE) ;
	}
	
	int* buffer = (int*) attach_shmem(shmemId) ;
	*buffer = 0 ;
	
	int emptySemKey = 100 ;
	int emptySemId = create_semaphore(emptySemKey) ;
	
	int fullSemKey = 101 ;
	int fullSemId = create_semaphore(fullSemKey) ;
	
	if ((emptySemId == -1) || (fullSemId == -1)) {
		perror("semaphore creation error") ;
		exit(EXIT_FAILURE) ;
	}
	
	init_semaphore(fullSemId, 0) ;
	init_semaphore(emptySemId, 1) ;
	
	while (*buffer >= 0) {
		down(emptySemId) ;
		if (!scanf("%d", buffer))
			*buffer = -1 ;
		up(fullSemId) ;
	}

	remove_semaphore(fullSemId) ;
	remove_semaphore(emptySemId) ;
	detach_shmem(buffer) ;
	remove_shmem(shmemId) ;	
}