Skip to content

Commit d11591a

Browse files
author
Junghee Lim
committed
Use better variable names for TLS examples
1 parent 86f047b commit d11591a

File tree

11 files changed

+98
-98
lines changed

11 files changed

+98
-98
lines changed

examples/ex_thread_local/ex.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
#include <stdio.h>
22

33
// Initialized thread-local object (.tdata):
4-
__thread int i = 4;
4+
__thread int initialized1 = 4;
55

66
// Uninitialized thread-local object (.tbss):
7-
__thread int j;
7+
__thread int uninitialized1;
88

9-
__thread long k = 10;
9+
__thread long initialized2 = 10;
1010

11-
__thread int l;
11+
__thread int uninitialized2;
1212

1313
int main()
1414
{
15-
i++;
16-
printf("%d\n", i);
17-
j++;
18-
printf("%d\n", j);
19-
k++;
20-
printf("%ld\n", k);
21-
l++;
22-
printf("%d\n", l);
15+
initialized1++;
16+
printf("%d\n", initialized1);
17+
uninitialized1++;
18+
printf("%d\n", uninitialized1);
19+
initialized2++;
20+
printf("%ld\n", initialized2);
21+
uninitialized2++;
22+
printf("%d\n", uninitialized2);
2323
}
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
#include <stdio.h>
22

3-
extern __thread int i;
3+
extern __thread int initialized1;
44

5-
extern __thread int j;
5+
extern __thread int uninitialized1;
66

7-
extern __thread long k;
7+
extern __thread long initialized2;
88

9-
extern __thread int l;
9+
extern __thread int uninitialized2;
1010

1111
int foo()
1212
{
13-
i++;
14-
printf("%d\n", i);
15-
j++;
16-
printf("%d\n", j);
17-
k++;
18-
printf("%ld\n", k);
19-
l++;
20-
printf("%d\n", l);
13+
initialized1++;
14+
printf("%d\n", initialized1);
15+
uninitialized1++;
16+
printf("%d\n", uninitialized1);
17+
initialized2++;
18+
printf("%ld\n", initialized2);
19+
uninitialized2++;
20+
printf("%d\n", uninitialized2);
2121

22-
return i + j + k + l;
22+
return initialized1 + uninitialized1 + initialized2 + uninitialized2;
2323
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Initialized thread-local object (.tdata):
2-
__thread int i = 4;
2+
__thread int initialized1 = 4;
33

44
// Uninitialized thread-local object (.tbss):
5-
__thread int j;
5+
__thread int uninitialized1;
66

7-
__thread long k = 10;
7+
__thread long initialized2 = 10;
88

9-
__thread int l;
9+
__thread int uninitialized2;

examples/ex_tls_initial_exec/Makefile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ CC="gcc"
22
CFLAGS=
33
EXEC=
44

5-
all: ex.c tls_def.c test.c
6-
$(CC) -fPIC -c ex.c "-ftls-model=initial-exec" $(CFLAGS) -o ex.o
5+
all: ex.c tls_def.c tls.c
6+
$(CC) -fPIC -c tls.c "-ftls-model=initial-exec" $(CFLAGS) -o tls.o
77
$(CC) -fPIC -c tls_def.c "-ftls-model=initial-exec" $(CFLAGS) -o tls_def.o
8-
$(CC) -shared -o libtls.so ex.o tls_def.o
9-
$(CC) test.c -fPIC $(CFLAGS) -ltls -L./ -o test
10-
@LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. $(EXEC) ./test > out.txt
8+
$(CC) -shared -o libtls.so tls.o tls_def.o
9+
$(CC) ex.c -fPIC $(CFLAGS) -ltls -L./ -o ex
10+
@LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. $(EXEC) ./ex > out.txt
1111
clean:
12-
rm -f test out.txt
13-
rm -fr test.unstripped *.old* *.s dl_files *.gtirb *.o *.so
12+
rm -f ex out.txt
13+
rm -fr ex.unstripped *.old* *.s dl_files *.gtirb *.o *.so
1414
check:
15-
@LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. $(EXEC) ./test > /tmp/res.txt
15+
@LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. $(EXEC) ./ex > /tmp/res.txt
1616
@ diff out.txt /tmp/res.txt && echo TEST OK

examples/ex_tls_initial_exec/ex.c

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,9 @@
11
#include <stdio.h>
22

3-
extern __thread int i;
3+
extern int foo(void);
44

5-
extern __thread int j;
6-
7-
extern __thread long k;
8-
9-
extern __thread int l;
10-
11-
int foo()
5+
int main(void)
126
{
13-
i++;
14-
printf("%d\n", i);
15-
j++;
16-
printf("%d\n", j);
17-
k++;
18-
printf("%ld\n", k);
19-
l++;
20-
printf("%d\n", l);
21-
22-
return i + j + k + l;
7+
printf("foo() = %d\n", foo());
8+
return 0;
239
}

examples/ex_tls_initial_exec/test.c

Lines changed: 0 additions & 9 deletions
This file was deleted.

examples/ex_tls_initial_exec/tls.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <stdio.h>
2+
3+
extern __thread int initialized1;
4+
5+
extern __thread int uninitialized1;
6+
7+
extern __thread long initialized2;
8+
9+
extern __thread int uninitialized2;
10+
11+
int foo()
12+
{
13+
initialized1++;
14+
printf("%d\n", initialized1);
15+
uninitialized1++;
16+
printf("%d\n", uninitialized1);
17+
initialized2++;
18+
printf("%ld\n", initialized2);
19+
uninitialized2++;
20+
printf("%d\n", uninitialized2);
21+
22+
return initialized1 + uninitialized1 + initialized2 + uninitialized2;
23+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Initialized thread-local object (.tdata):
2-
__thread int i = 4;
2+
__thread int initialized1 = 4;
33

44
// Uninitialized thread-local object (.tbss):
5-
__thread int j;
5+
__thread int uninitialized1;
66

7-
__thread long k = 10;
7+
__thread long initialized2 = 10;
88

9-
__thread int l;
9+
__thread int uninitialized2;
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
#include <stdio.h>
22

3-
extern __thread int i;
3+
extern __thread int initialized1;
44

5-
extern __thread int j;
5+
extern __thread int uninitialized1;
66

7-
extern __thread long k;
7+
extern __thread long initialized2;
88

9-
extern __thread int l;
9+
extern __thread int uninitialized2;
1010

1111
int foo()
1212
{
13-
i++;
14-
printf("%d\n", i);
15-
j++;
16-
printf("%d\n", j);
17-
k++;
18-
printf("%ld\n", k);
19-
l++;
20-
printf("%d\n", l);
13+
initialized1++;
14+
printf("%d\n", initialized1);
15+
uninitialized1++;
16+
printf("%d\n", uninitialized1);
17+
initialized2++;
18+
printf("%ld\n", initialized2);
19+
uninitialized2++;
20+
printf("%d\n", uninitialized2);
2121

22-
return i + j + k + l;
22+
return initialized1 + uninitialized1 + initialized2 + uninitialized2;
2323
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Initialized thread-local object (.tdata):
2-
__thread int i = 4;
2+
__thread int initialized1 = 4;
33

44
// Uninitialized thread-local object (.tbss):
5-
__thread int j;
5+
__thread int uninitialized1;
66

7-
__thread long k = 10;
7+
__thread long initialized2 = 10;
88

9-
__thread int l;
9+
__thread int uninitialized2;

0 commit comments

Comments
 (0)