fix usertrace
[lttv.git] / ltt-usertrace / sample-thread-fast.c
1
2 #include <pthread.h>
3 #include <stdio.h>
4 #include <unistd.h>
5 #include <stdlib.h>
6
7 #define LTT_TRACE
8 #define LTT_TRACE_FAST
9 #include <ltt/ltt-facility-user_generic.h>
10
11
12 void *thr1(void *arg)
13 {
14 int i;
15 ltt_thread_init(); /* This init is not required : it will be done
16 automatically anyways at the first tracing call site */
17 printf("thread 1, thread id : %lu, pid %lu\n", pthread_self(), getpid());
18
19 for(i=0; i<100000; i++) {
20 trace_user_generic_string("Hello world! Have a nice day.");
21 }
22 pthread_exit((void*)1);
23 }
24
25
26 /* Example of a _bad_ thread, which still works with the tracing */
27 void *thr2(void *arg)
28 {
29 int i;
30 /* See ? no init */
31 printf("thread 2, thread id : %lu, pid %lu\n", pthread_self(), getpid());
32
33 for(i=0; i<100000; i++) {
34 trace_user_generic_string("Hello world! Have a nice day.");
35 }
36 /* This thread is a bad citizen : returning like this will cause its cancel
37 * routines not to be executed. This is still detected by the tracer, but only
38 * when the complete process dies. This is not recommended if you create a
39 * huge amount of threads */
40 return ((void*)2);
41 }
42
43
44 int main()
45 {
46 int err;
47 pthread_t tid1, tid2;
48 void *tret;
49
50 printf("Will trace the following string : Hello world! Have a nice day.\n");
51 printf("It will stop automatically.\n");
52 printf("See the result file in /tmp/ltt-usertrace.\n");
53
54 printf("thread main, thread id : %lu, pid %lu\n", pthread_self(), getpid());
55 err = pthread_create(&tid1, NULL, thr1, NULL);
56 if(err!=0) exit(1);
57
58 err = pthread_create(&tid2, NULL, thr2, NULL);
59 if(err!=0) exit(1);
60
61 err = pthread_join(tid1, &tret);
62 if(err!= 0) exit(1);
63
64 err = pthread_join(tid2, &tret);
65 if(err!= 0) exit(1);
66
67 return 0;
68 }
This page took 0.032164 seconds and 4 git commands to generate.