lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <tls.h> |
| 3 | |
| 4 | #define TLS_VAR_INIT_VALUE 99 |
| 5 | |
| 6 | #ifdef USE_TLS |
| 7 | __thread int tls_var __attribute__((tls_model("global-dynamic"))); |
| 8 | static __thread int local_tls_var __attribute__((tls_model("local-dynamic"))); |
| 9 | #endif |
| 10 | |
| 11 | void __attribute__((constructor)) libtls_ctor(void); |
| 12 | void libtls_ctor(void) |
| 13 | { |
| 14 | printf("libtls: constructor!\n"); |
| 15 | #ifdef USE_TLS |
| 16 | local_tls_var = TLS_VAR_INIT_VALUE; |
| 17 | tls_var = local_tls_var; |
| 18 | #endif |
| 19 | } |
| 20 | |
| 21 | void __attribute__((destructor)) libtls_dtor(void); |
| 22 | void libtls_dtor(void) |
| 23 | { |
| 24 | printf("libtls: destructor!\n"); |
| 25 | } |