1/* 2 * Copyright (c) 2002, Intel Corporation. All rights reserved. 3 * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com 4 * This file is licensed under the GPL license. For the full content 5 * of this license, see the COPYING file at the top level of this 6 * source tree. 7 8 * Test that pthread_mutex_init() 9 * initializes a mutex referenced by 'mutex' with attributes specified 10 * by 'attr'. If 'attr' is NULL, the default mutex attributes are used. 11 * The effect shall be the same as passing the address of a default 12 * mutex attributes. 13 14 * NOTE: There is no direct way to judge if two mutexes have the same effect, 15 * thus this test does not cover the statement in the last sentence. 16 * 17 */ 18 19#include <pthread.h> 20#include <stdio.h> 21#include "posixtest.h" 22 23int main() 24{ 25 pthread_mutexattr_t mta; 26 pthread_mutex_t mutex1, mutex2; 27 int rc; 28 29 /* Initialize a mutex attributes object */ 30 if((rc=pthread_mutexattr_init(&mta)) != 0) { 31 fprintf(stderr,"Error at pthread_mutexattr_init(), rc=%d\n",rc); 32 return PTS_UNRESOLVED; 33 } 34 35 /* Initialize mutex1 with the default mutex attributes */ 36 if((rc=pthread_mutex_init(&mutex1,&mta)) != 0) { 37 fprintf(stderr,"Fail to initialize mutex1, rc=%d\n",rc); 38 printf("Test FAILED\n"); 39 return PTS_FAIL; 40 } 41 42 /* Initialize mutex2 with NULL attributes */ 43 if((rc=pthread_mutex_init(&mutex2,NULL)) != 0) { 44 fprintf(stderr,"Fail to initialize mutex2, rc=%d\n",rc); 45 printf("Test FAILED\n"); 46 return PTS_FAIL; 47 } 48 49 printf("Test PASSED\n"); 50 return PTS_PASS; 51} 52