Home | History | Annotate | Download | only in pthread_mutex_unlock
      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_unlock()
      9  *   shall release the mutex object 'mutex'.
     10 
     11  * Steps:
     12  *   -- Initilize a mutex object
     13  *   -- Get the mutex using pthread_mutex_lock()
     14  *   -- Release the mutex using pthread_mutex_unlock()
     15  *   -- Try to get the mutex using pthread_mutex_trylock()
     16  *   -- Release the mutex using pthread_mutex_unlock()
     17  *
     18  */
     19 
     20 #include <pthread.h>
     21 #include <stdio.h>
     22 #include <errno.h>
     23 #include "posixtest.h"
     24 
     25 pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
     26 
     27 int main(void)
     28 {
     29 	int rc;
     30 
     31 	/* Get the mutex using pthread_mutex_lock() */
     32 	if ((rc = pthread_mutex_lock(&mutex)) != 0) {
     33 		fprintf(stderr, "Error at pthread_mutex_lock(), rc=%d\n", rc);
     34 		return PTS_UNRESOLVED;
     35 	}
     36 
     37 	/* Release the mutex using pthread_mutex_unlock() */
     38 	if ((rc = pthread_mutex_unlock(&mutex)) != 0) {
     39 		printf("Test FAILED\n");
     40 		return PTS_FAIL;
     41 	}
     42 
     43 	/* Get the mutex using pthread_mutex_trylock() */
     44 	if ((rc = pthread_mutex_trylock(&mutex)) != 0) {
     45 		printf("Test FAILED\n");
     46 		return PTS_FAIL;
     47 	}
     48 
     49 	/* Release the mutex using pthread_mutex_unlock() */
     50 	if ((rc = pthread_mutex_unlock(&mutex)) != 0) {
     51 		printf("Test FAILED\n");
     52 		return PTS_FAIL;
     53 	}
     54 
     55 	printf("Test PASSED\n");
     56 	return PTS_PASS;
     57 }
     58