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