Home | History | Annotate | Download | only in pthread_mutex_destroy
      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_destroy()
      9  *   shall destroy the mutex referenced by 'mutex'; the mutex object in effect
     10  *   becomes uninitialized.
     11  *
     12  */
     13 
     14 #include <pthread.h>
     15 #include <stdio.h>
     16 #include "posixtest.h"
     17 
     18 pthread_mutex_t mutex1, mutex2;
     19 pthread_mutex_t mutex3 = PTHREAD_MUTEX_INITIALIZER;
     20 
     21 int main(void)
     22 {
     23 	pthread_mutexattr_t mta;
     24 	int rc;
     25 
     26 	/* Initialize a mutex attributes object */
     27 	if ((rc = pthread_mutexattr_init(&mta)) != 0) {
     28 		fprintf(stderr, "Error at pthread_mutexattr_init(), rc=%d\n",
     29 			rc);
     30 		return PTS_UNRESOLVED;
     31 	}
     32 
     33 	/* Initialize mutex1 with the default mutex attributes */
     34 	if ((rc = pthread_mutex_init(&mutex1, &mta)) != 0) {
     35 		fprintf(stderr, "Fail to initialize mutex1, rc=%d\n", rc);
     36 		return PTS_UNRESOLVED;
     37 	}
     38 
     39 	/* Initialize mutex2 with NULL attributes */
     40 	if ((rc = pthread_mutex_init(&mutex2, NULL)) != 0) {
     41 		fprintf(stderr, "Fail to initialize mutex2, rc=%d\n", rc);
     42 		return PTS_UNRESOLVED;
     43 	}
     44 
     45 	/* Destroy the mutex attributes object */
     46 	if ((rc = pthread_mutexattr_destroy(&mta)) != 0) {
     47 		fprintf(stderr, "Error at pthread_mutexattr_destroy(), rc=%d\n",
     48 			rc);
     49 		return PTS_UNRESOLVED;
     50 	}
     51 
     52 	/* Destroy mutex1 */
     53 	if ((rc = pthread_mutex_destroy(&mutex1)) != 0) {
     54 		fprintf(stderr, "Fail to destroy mutex1, rc=%d\n", rc);
     55 		printf("Test FAILED\n");
     56 		return PTS_FAIL;
     57 	}
     58 
     59 	/* Destroy mutex2 */
     60 	if ((rc = pthread_mutex_destroy(&mutex2)) != 0) {
     61 		fprintf(stderr, "Fail to destroy mutex2, rc=%d\n", rc);
     62 		printf("Test FAILED\n");
     63 		return PTS_FAIL;
     64 	}
     65 
     66 	/* Destroy mutex3 */
     67 	if ((rc = pthread_mutex_destroy(&mutex3)) != 0) {
     68 		fprintf(stderr, "Fail to destroy mutex3, rc=%d\n", rc);
     69 		printf("Test FAILED\n");
     70 		return PTS_FAIL;
     71 	}
     72 
     73 	printf("Test PASSED\n");
     74 	return PTS_PASS;
     75 }
     76