initial import
[staff/goc4/2018bti7061.git] / c-6-additional / examples / c-paralelism / thread1.c
1 /* http://www.thegeekstuff.com/2012/04/create-threads-in-linux/ */
2 #include<stdio.h>
3 #include<string.h>
4 #include<pthread.h>
5 #include<stdlib.h>
6 #include<unistd.h>
7
8 pthread_t tid[2];
9
10 void* doSomeThing(void *arg)
11 {
12 unsigned long i = 0;
13 pthread_t id = pthread_self();
14
15 if(pthread_equal(id,tid[0]))
16 {
17 printf("\n First thread processing\n");
18 }
19 else
20 {
21 printf("\n Second thread processing\n");
22 }
23
24 for(i=0; i<(0xFFFFFFFF);i++);
25
26 return NULL;
27 }
28
29 int main(void)
30 {
31 int i = 0;
32 int err;
33
34 while(i < 2)
35 {
36 err = pthread_create(&(tid[i]), NULL, &doSomeThing, NULL);
37 if (err != 0)
38 printf("\ncan't create thread :[%s]", strerror(err));
39 else
40 printf("\n Thread created successfully\n");
41
42 i++;
43 }
44
45 sleep(5);
46 return 0;
47 }