new ltt-usertrace
[lttv.git] / ltt-usertrace / sample-thread.c
1
2 #include <pthread.h>
3 #include <stdio.h>
4 #include <unistd.h>
5 #include <stdlib.h>
6
7 #define LTT_TRACE
8 #include <ltt/ltt-facility-user_generic.h>
9
10
11 void *thr1(void *arg)
12 {
13 printf("thread 1, thread id : %lu, pid %lu\n", pthread_self(), getpid());
14
15 while(1) {
16 trace_user_generic_string("Hello world! Have a nice day.");
17 sleep(2);
18 }
19
20 return ((void*)1);
21
22 }
23
24 void *thr2(void *arg)
25 {
26 printf("thread 2, thread id : %lu, pid %lu\n", pthread_self(), getpid());
27 sleep(1);
28 while(1) {
29 trace_user_generic_string("Hello world! Have a nice day.");
30 sleep(2);
31 }
32 return ((void*)2);
33 }
34
35
36 int main()
37 {
38 int err;
39 pthread_t tid1, tid2;
40 void *tret;
41
42 printf("Will trace the following string : Hello world! Have a nice day.\n");
43 printf("Press CTRL-C to stop.\n");
44 printf("thread main, thread id : %lu, pid %lu\n", pthread_self(), getpid());
45 err = pthread_create(&tid1, NULL, thr1, NULL);
46 if(err!=0) exit(1);
47
48 err = pthread_create(&tid2, NULL, thr2, NULL);
49 if(err!=0) exit(1);
50
51 err = pthread_join(tid1, &tret);
52 if(err!= 0) exit(1);
53
54 err = pthread_join(tid2, &tret);
55 if(err!= 0) exit(1);
56
57 return 0;
58 }
This page took 0.03146 seconds and 4 git commands to generate.