This example shows how our trace application
runs and the results we will obtain.
Consider this program, it uses NPTL functions we
want to trace:
example.c
pthread_barrier_t bar;
pthread_t th;
void function()
{
printf("second
thread before the barrier \n");
pthread_barrier_wait(&bar);
printf("second
thread after the barrier \n");
}
int main()
{
printf("main
thread is beginning \n");
pthread_barrier_init(&bar,
NULL, 2);
pthread_create(&th,
NULL, fonction, NULL);
pthread_barrier_wait(&bar);
printf("main
thread has finished \n");
pthread_join(&th,NULL);
pthread_barrier_destroy(&bar);
return
0;
}
In this program we use four Nptl functions: pthread_barrier_init,
pthread_create, pthread_barrier_wait, pthread_barrier_destroy.
It returns: "main thread is
beginning"
"second thread before the barrier"
"second thread after the barrier"
"main thread has finished"
The trace function will return us a text file like this:
1."Thread 0x40015360
initializes barrier 0x42130a14, lock= 0, left = 2 "
/*EVT_BARRIER_INIT*/
2."Thread 0x40015360
creates thread 0x51103287"
/*EVT_THREAD_INIT*/
3."Barrier 0x42130a14 is required
by thread 0x40015360,
lock = 0 " // EVT_BARRIER_LOCK_REQUIRE
4."Barrier 0x42130a14
is taken by thread 0x40015360,
lock=1"
//
EVT_BARRIER_LOCK_TAKEN
5."Thread 0x40015360
enters the barrier 0x42130a14,
left =1 "
/*EVT_BARRIER_LEFT_DEC */
6."Barrier 0x42130a14 is
required by thread 0x51103287,
lock = 1"
/* EVT_BARRIER_LOCK_REQUIRE*/
7."Thread: 0x51103287 is
blocked"
/*EVT_THREAD_STATE_WAIT*/
7."Barrier 0x42130a14 is
freed by thread 0x40015360
,lock= 0"
/* EVT_BARRIER_LOCK_FREE*/
8."Thread 0x51103287 is
resumed"
/* EVT_THREAD_STATE_WAKE */
8."Barrier 0x42130a14 is
taken by thread 0x51103287,
lock= 0"
/* EVT_BARRIER_LOCK_TAKEN*/
9."Thread 0x40015360 is
blocked"
/*EVT_THREAD_STATE_WAIT*/
9."Thread 0x51103287
enters the barrier 0x42130a14,
left = 0"
/*EVT_BARRIER_LEFT_DEC */
10."Thread 0x51103287
leaves the barrier 0x42130a14,
left = 1"
/*
EVT_BARRIER_LEFT_INC*/
10."Thread 0x40015360 is
resumed"
/* EVT_THREAD_STATE_WAKE */
11."Thread 0x40015360
leaves the barrier 0x42130a14,
left = 2"
/*
EVT_BARRIER_LEFT_INC*/
11."Barrier 0x42130a14 is
freed by thread 0x40015360
,lock= 0"
/* EVT_BARRIER_LOCK_FREE*/
12."Thread 0x40015360 is
blocked"
/*EVT_THREAD_STATE_WAIT*/
13. " Thread 0x40015360 is
resumed"
/* EVT_THREAD_STATE_WAKE */
14."Barrier0x42130a14 is
required by thread 0x40015360,
lock =0"
// EVT_BARRIER_LOCK_REQUIRE
14."Thread 0x40015360 is
blocked"
/*EVT_THREAD_STATE_WAIT*/
14."Thread 0x40015360 is
waiting for thread 0x51103287"
/*EVT_THREAD_JOIN*/
15."Thread 0x40015360 is
resumed"
/* EVT_THREAD_STATE_WAKE */
16."Barrier 0x42130a14 is
destroyed by thread 0x40015360,
lock =1"
/*
EVT_BARRIER_DESTROY*/
Numbers at the beginning of each
description represent the time, which is given by the computer clock.
back to
"index"