/***************************************************
*--------------------------------------------------
* Creat : 2001. 04. 10 (programed by Cori-Young )
* Site: http://www.byoneself.co.kr
* Update :
*--------------------------------------------------
* Compile : cc -o xxx xxx.c -lpthread -lrt
*--------------------------------------------------
* Machine hardware: sun4u
* OS version: 5.7
* Processor type: sparc
* Hardware: SUNW,Ultra-60
***************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#define _MULTI_THREADED
static void checkResults(char *string, int rc) {
if (rc) {
printf("Error on : %s, rc=%d", string, rc);
exit(EXIT_FAILURE);
}
return;
}
pthread_mutex_t mutex;
int main(int argc, char **argv)
{
int rc=0;
pthread_mutexattr_t mta;
printf("Entering testcasen");
printf("Create a default mutex attributen");
rc = pthread_mutexattr_init(&mta);
checkResults("pthread_mutexattr_initn", rc);
printf("Create the mutex using a mutex attributes objectn");
rc = pthread_mutex_init(&mutex, &mta);
checkResults("pthread_mutex_init(mta)n", rc);
printf("- At this point, the mutex with its default attributesn");
printf("- Can be used from any threads that want to use itn");
printf("Destroy mutex attributen");
rc = pthread_mutexattr_destroy(&mta);
checkResults("pthread_mutexattr_destroy()n", rc);
printf("Destroy mutexn");
rc = pthread_mutex_destroy(&mutex);
checkResults("pthread_mutex_destroy()n", rc);
printf("Main completedn");
return 0;
} |
|