Home | History | Annotate | Download | only in pthread_mutexattr_setpshared
      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_mutexattr_setpshared()
      9  *
     10  * The default value of the 'pshared' attribute is PTHREAD_PROCESS_PRIVATE.
     11  *
     12  * Steps:
     13  * 1.  Initialize a pthread_mutexattr_t object with pthread_mutexattr_init()
     14  * 2.  Call pthread_mutexattr_getpshared() to check if the process-shared
     15  *     attribute is set as the default value PTHREAD_PROCESS_PRIVATE.
     16  *
     17  */
     18 
     19 #include <pthread.h>
     20 #include <stdio.h>
     21 #include "posixtest.h"
     22 
     23 int main(void)
     24 {
     25 
     26 	/* Make sure there is process-shared capability. */
     27 #ifndef PTHREAD_PROCESS_SHARED
     28 	fprintf(stderr,
     29 		"process-shared attribute is not available for testing\n");
     30 	return PTS_UNRESOLVED;
     31 #endif
     32 
     33 	pthread_mutexattr_t mta;
     34 	int pshared;
     35 
     36 	/* Initialize a mutex attributes object */
     37 	if (pthread_mutexattr_init(&mta) != 0) {
     38 		perror("Error at pthread_mutexattr_init()\n");
     39 		return PTS_UNRESOLVED;
     40 	}
     41 
     42 	/* The default 'pshared' attribute should be PTHREAD_PROCESS_PRIVATE  */
     43 	if (pthread_mutexattr_getpshared(&mta, &pshared) != 0) {
     44 		fprintf(stderr,
     45 			"Error obtaining the attribute process-shared\n");
     46 		return PTS_UNRESOLVED;
     47 	}
     48 
     49 	/* Make sure that the default is PTHREAD_PROCESS_PRIVATE. */
     50 	if (pshared != PTHREAD_PROCESS_PRIVATE) {
     51 		printf("Test FAILED: Incorrect default pshared value: %d\n",
     52 		       pshared);
     53 		return PTS_FAIL;
     54 	}
     55 
     56 	printf("Test PASSED\n");
     57 	return PTS_PASS;
     58 }
     59