1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
void saying_pthread_name(void* ptr);
int value=1;
int
main(void)
{
pthread_t wthread, bthread, rthread;
char* wname = "white";
char* bname = "black";
char* rname = "red";
pthread_attr_t* pthread_attr_default = NULL;
pthread_create(&wthread, pthread_attr_default,
(void*)&saying_pthread_name, (void*) wname);
pthread_create(&bthread, pthread_attr_default,
(void*)&saying_pthread_name, (void*) bname);
pthread_create(&rthread, pthread_attr_default,
(void*)&saying_pthread_name, (void*) rname);
pthread_join(wthread,NULL);
//printf("%d\n", value);
pthread_join(rthread,NULL);
pthread_join(bthread,NULL);
exit(0);
}
void
saying_pthread_name(void* ptr)
{
char* message;
message = (char*)ptr;
printf("I am a %s pthread and the value is %d \n", message, value);
value = value+1;
}
|