tst-tlsmod-at-ctor.c 552 B

12345678910111213141516171819202122232425
  1. #include <stdio.h>
  2. #include <tls.h>
  3. #define TLS_VAR_INIT_VALUE 99
  4. #ifdef USE_TLS
  5. __thread int tls_var __attribute__((tls_model("global-dynamic")));
  6. static __thread int local_tls_var __attribute__((tls_model("local-dynamic")));
  7. #endif
  8. void __attribute__((constructor)) libtls_ctor(void);
  9. void libtls_ctor(void)
  10. {
  11. printf("libtls: constructor!\n");
  12. #ifdef USE_TLS
  13. local_tls_var = TLS_VAR_INIT_VALUE;
  14. tls_var = local_tls_var;
  15. #endif
  16. }
  17. void __attribute__((destructor)) libtls_dtor(void);
  18. void libtls_dtor(void)
  19. {
  20. printf("libtls: destructor!\n");
  21. }