• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_cond_destroy()
9  *   shall destroy the condition variable referenced by 'cond';
10  *   the condition variable object in effect becomes uninitialized.
11  *
12  */
13 
14 #include <pthread.h>
15 #include <stdio.h>
16 #include "posixtest.h"
17 
18 static pthread_cond_t cond1, cond2;
19 static pthread_cond_t cond3 = PTHREAD_COND_INITIALIZER;
20 
main(void)21 int main(void)
22 {
23 	pthread_condattr_t condattr;
24 	int rc;
25 
26 	/* Initialize a condition variable attribute object */
27 	if ((rc = pthread_condattr_init(&condattr)) != 0) {
28 		fprintf(stderr, "Error at pthread_condattr_init(), rc=%d\n",
29 			rc);
30 		return PTS_UNRESOLVED;
31 	}
32 
33 	/* Initialize cond1 with the default condition variable attribute */
34 	if ((rc = pthread_cond_init(&cond1, &condattr)) != 0) {
35 		fprintf(stderr, "Fail to initialize cond1, rc=%d\n", rc);
36 		return PTS_UNRESOLVED;
37 	}
38 
39 	/* Initialize cond2 with NULL attributes */
40 	if ((rc = pthread_cond_init(&cond2, NULL)) != 0) {
41 		fprintf(stderr, "Fail to initialize cond2, rc=%d\n", rc);
42 		return PTS_UNRESOLVED;
43 	}
44 
45 	/* Destroy the condition variable attribute object */
46 	if ((rc = pthread_condattr_destroy(&condattr)) != 0) {
47 		fprintf(stderr, "Error at pthread_condattr_destroy(), rc=%d\n",
48 			rc);
49 		return PTS_UNRESOLVED;
50 	}
51 
52 	/* Destroy cond1 */
53 	if ((rc = pthread_cond_destroy(&cond1)) != 0) {
54 		fprintf(stderr, "Fail to destroy cond1, rc=%d\n", rc);
55 		printf("Test FAILED\n");
56 		return PTS_FAIL;
57 	}
58 
59 	/* Destroy cond2 */
60 	if ((rc = pthread_cond_destroy(&cond2)) != 0) {
61 		fprintf(stderr, "Fail to destroy cond2, rc=%d\n", rc);
62 		printf("Test FAILED\n");
63 		return PTS_FAIL;
64 	}
65 
66 	/* Destroy cond3 */
67 	if ((rc = pthread_cond_destroy(&cond3)) != 0) {
68 		fprintf(stderr, "Fail to destroy cond3, 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