Untitled
unknown
c_cpp
4 years ago
592 B
4
Indexable
#include <stdio.h> #include <stdlib.h> #include <assert.h> #include <time.h> #include <dlfcn.h> __thread volatile int tls __attribute__((tls_model("global-dynamic"))); static int __attribute__ ((noinline)) readtls(void) { return tls; } static void __attribute__ ((noinline)) writetls(int v) { tls = v; } int main(void) { volatile int i; time_t ts; dlopen("libuuid.so.1.3.0", RTLD_NOW); ts = time(NULL); writetls(0); for (i = 1; i < 0x2000000; ++i) { volatile int j = readtls(); assert(j + 1 == i); writetls(i); } printf("Time used: %lu\n", time(NULL) - ts); return 0; }
Editor is loading...