tst-tlsmod-at-ctor.c 535 B

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