/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * This test use semaphore to protect critical section between several * processes. */ #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define SEM_NAME "/tmp/semaphore" #define BUF_SIZE 200 #define DEFAULT_THREADS 5 int main(int argc, char *argv[]) { sem_t *sem_lock; int shared = 1; int value = 1; pid_t pid=0; int i, num=0; char buf[BUF_SIZE]; char *c; #ifndef _POSIX_SEMAPHORES printf("_POSIX_SEMAPHORES is not defined \n"); return PTS_UNRESOLVED; #endif if ( (2 != argc) || (( num = atoi(argv[1])) <= 0)) { fprintf(stdout, "Usage: %s number_of_processes\n", argv[0]); printf("Set num_of_processes to default value %d \n", DEFAULT_THREADS); num = DEFAULT_THREADS; } sem_lock = (sem_t *)malloc(sizeof(sem_t)); if (-1 == sem_init(sem_lock, shared, value)) { perror("sem_init didn't return success\n"); return PTS_UNRESOLVED; } for (i=1; i