CS3413/Assignment3/examples/5-pthread_detach.c

19 lines
568 B
C
Raw Normal View History

2023-10-08 23:19:49 -03:00
#include<pthread.h>
#include<stdio.h>
void* run (void* arg){
printf("Hello from run\n");
return NULL;
}
int main(){
pthread_t thread;
pthread_create(&thread, NULL, &run, NULL);
pthread_detach(thread);
// This command will make thread detached. This means the resources will be released
// upon the thread's completion - calling return
// However, detached threads cannot be joined, which means if you care about the result
// of the thread execution - you should not be using pthread_detach
printf("In main");
return 0;
}