Home | History | Annotate | Download | only in pthread_mutex_init
      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 
     23 int main(void)
     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",
     32 			rc);
     33 		return PTS_UNRESOLVED;
     34 	}
     35 
     36 	/* Initialize mutex1 with the default mutex attributes */
     37 	if ((rc = pthread_mutex_init(&mutex1, &mta)) != 0) {
     38 		fprintf(stderr, "Fail to initialize mutex1, rc=%d\n", rc);
     39 		printf("Test FAILED\n");
     40 		return PTS_FAIL;
     41 	}
     42 
     43 	/* Initialize mutex2 with NULL attributes */
     44 	if ((rc = pthread_mutex_init(&mutex2, NULL)) != 0) {
     45 		fprintf(stderr, "Fail to initialize mutex2, rc=%d\n", rc);
     46 		printf("Test FAILED\n");
     47 		return PTS_FAIL;
     48 	}
     49 
     50 	printf("Test PASSED\n");
     51 	return PTS_PASS;
     52 }
     53