/* from https://sourceware.org/ml/libc-help/2011-04/msg00000.html */ /* test.c */ /* Compile with "cc -o test test.c -lpthread" */ #include #include #include #include int main(void) { int i; void *handle; pthread_t pt; void *(*do_something)(void *); handle = dlopen("./test_lib.so", RTLD_LAZY); if (!handle) { perror("dlopen"); return EXIT_FAILURE; } do_something = dlsym(handle, "do_something"); if (!do_something) { perror("dlsym"); return EXIT_FAILURE; } for (i = 0; i < 10000; i++) { if (pthread_create(&pt, NULL, do_something, NULL)) { perror("pthread_create"); return EXIT_FAILURE; } if (pthread_join(pt, NULL)) { perror("pthread_join"); return EXIT_FAILURE; } } if (dlclose(handle)) { perror("dlclose"); return EXIT_FAILURE; } return EXIT_SUCCESS; } /* test_lib.c */ /* Compile with "cc -o test_lib.so test_lib.c -fPIC -shared" */ #include static __thread int a; void *do_something(void *arg) { a = 666; return NULL; }