/***************************************************
*--------------------------------------------------
* 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;
}
void showDetachState(pthread_attr_t *a)
{
int rc=0;
int state=0;
printf("Get detach staten");
rc = pthread_attr_getdetachstate(a, &state);
checkResults("pthread_attr_getdetachstate()n", rc);
printf("The thread attributes object indicates: ");
switch (state) {
case PTHREAD_CREATE_DETACHED:
printf("DETACHEDn");
break;
case PTHREAD_CREATE_JOINABLE:
printf("JOINABLEn");
break;
}
return;
}
int main(int argc, char **argv)
{
pthread_t thread;
int rc=0;
pthread_attr_t pta;
printf("Enter Testcase - %sn", argv[0]);
printf("Create a default thread attributes objectn");
rc = pthread_attr_init(&pta);
checkResults("pthread_attr_init()n", rc);
showDetachState(&pta);
printf("Set the detach staten");
rc = pthread_attr_setdetachstate(&pta, PTHREAD_CREATE_DETACHED);
checkResults("pthread_attr_setdetachstate()n", rc);
showDetachState(&pta);
printf("Destroy thread attributes objectn");
rc = pthread_attr_destroy(&pta);
checkResults("pthread_attr_destroy()n", rc);
printf("Main completedn");
return 0;
} |
|