Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F4140710
tls_test.c
alfredo (Alfredo Dal'Ava Júnior)
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
alfredo
Jan 14 2019, 4:13 PM
2019-01-14 16:13:02 (UTC+0)
Size
737 B
Referenced Files
None
Subscribers
None
tls_test.c
View Options
#include
<pthread.h>
#include
<stdio.h>
#include
<threads.h>
#include
<unistd.h>
#include
<assert.h>
thread_local
int
tlocal
=
0
;
void
*
increment_func
(
void
*
x_void_ptr
)
{
while
(
tlocal
<
2000
)
{
tlocal
++
;
usleep
(
10
);
}
printf
(
"[thread #1] tlocal = %d
\n
"
,
tlocal
);
assert
(
tlocal
==
2000
);
return
NULL
;
}
int
main
()
{
tlocal
=
0
;
pthread_t
increment_thread
;
if
(
pthread_create
(
&
increment_thread
,
NULL
,
increment_func
,
NULL
))
{
fprintf
(
stderr
,
"Error creating thread
\n
"
);
return
1
;
}
while
(
tlocal
<
100
)
{
tlocal
++
;
}
if
(
pthread_join
(
increment_thread
,
NULL
))
{
fprintf
(
stderr
,
"Error joining thread
\n
"
);
return
2
;
}
printf
(
"[thread #0] tlocal = %d
\n
"
,
tlocal
);
assert
(
tlocal
==
100
);
return
0
;
}
File Metadata
Details
Attached
Mime Type
text/x-c
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1713179
Default Alt Text
tls_test.c (737 B)
Attached To
Mode
D18807: silence cast-align warnings from clang on powerpc64
Attached
Detach File
Event Timeline
Log In to Comment