1 /* 2 * Copyright (c) 2002, Intel Corporation. All rights reserved. 3 * This file is licensed under the GPL license. For the full content 4 * of this license, see the COPYING file at the top level of this 5 * source tree. 6 * 7 * pthread_barrierattr_init() 8 * 9 * After a barrier attributes object has been used to initialize one or more barriers 10 * any function affecting the attributes object (including destruction) shall not 11 * affect any previously initialized barrier. 12 * 13 */ 14 15 #define _XOPEN_SOURCE 600 16 #include <pthread.h> 17 #include <stdio.h> 18 #include <stdlib.h> 19 #include <unistd.h> 20 #include <signal.h> 21 #include <errno.h> 22 #include <string.h> 23 #include "posixtest.h" 24 25 #define BARRIER_NUM 100 26 27 int main(void) 28 { 29 int rc; 30 pthread_barrierattr_t ba; 31 pthread_barrier_t barriers[BARRIER_NUM]; 32 int cnt; 33 34 /* Initialize the barrier attribute object */ 35 rc = pthread_barrierattr_init(&ba); 36 if (rc != 0) { 37 printf 38 ("Test FAILED: Error while initialize attribute object\n"); 39 return PTS_FAIL; 40 } 41 42 /* Initialize BARRIER_NUM barrier objects, with count==1 */ 43 for (cnt = 0; cnt < BARRIER_NUM; cnt++) { 44 if (pthread_barrier_init(&barriers[cnt], &ba, 1) != 0) { 45 printf("Error at %dth initialization\n", cnt); 46 return PTS_UNRESOLVED; 47 } 48 } 49 50 /* Destroy barrier attribute object */ 51 rc = pthread_barrierattr_destroy(&ba); 52 if (rc != 0) { 53 printf("Error at pthread_barrierattr_destroy() " 54 "return code: %d, %s", rc, strerror(rc)); 55 return PTS_UNRESOLVED; 56 } 57 58 /* Check that pthread_barrier_wait can still be performed, even after the attributes 59 * object has been destroyed */ 60 for (cnt = 0; cnt < BARRIER_NUM; cnt++) { 61 rc = pthread_barrier_wait(&barriers[cnt]); 62 if (rc != 0 && rc != PTHREAD_BARRIER_SERIAL_THREAD) { 63 printf("Test Fail: Error at %dth wait, %s\n", cnt, 64 strerror(rc)); 65 return PTS_FAIL; 66 } 67 } 68 69 /* Cleanup */ 70 for (cnt = 0; cnt < BARRIER_NUM; cnt++) { 71 rc = pthread_barrier_destroy(&barriers[cnt]); 72 if (rc != 0) { 73 printf("Error at %dth destruction, %s\n", cnt, 74 strerror(rc)); 75 return PTS_UNRESOLVED; 76 } 77 } 78 79 printf("Test PASSED\n"); 80 return PTS_PASS; 81 } 82