Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rdemeter
GitHub Repository: rdemeter/so
Path: blob/master/lab7/ex_thread.c
221 views
1
#include<stdio.h>
2
#include<pthread.h>
3
#include<stdlib.h>
4
#include<string.h>
5
#include<unistd.h>
6
7
void* thread_function(void)
8
{
9
char *a = malloc(12);
10
strcpy(a, "hello world");
11
//sleep(10);
12
pthread_exit((void*)a);
13
}
14
15
int main()
16
{
17
pthread_t thread_id;
18
char *b = NULL;
19
pthread_create (&thread_id, NULL, (void*)&thread_function, NULL);
20
21
//
22
//While the created thread is running, the main thread can perform other tasks.
23
24
//here we are reciving one pointer value so to use that we need double pointer
25
pthread_join(thread_id,(void**)&b);
26
27
printf("b is %s\n", b);
28
free(b); // lets free the memory
29
}
30
31