jjzjj

c++ - LD_PRELOAD 和线程局部变量

我有一个共享库(libtest.cpp)和一个简单程序(test.cpp)。我希望他们共享一个线程局部变量gVar。共享库通过LD_PRELOAD链接。这是共享库libtest.cpp的代码:#include__threadintgVar;voidprint_gVar(){printf("%d\n",gVar);}下面是test.cpp的代码。#include__threadintgVar;void__attribute__((weak))print_gVar();intmain(){gVar=10;print_gVar();return0;}然后我使用以下脚本来编译和运行它们。g++

c++ - LD_PRELOAD 和线程局部变量

我有一个共享库(libtest.cpp)和一个简单程序(test.cpp)。我希望他们共享一个线程局部变量gVar。共享库通过LD_PRELOAD链接。这是共享库libtest.cpp的代码:#include__threadintgVar;voidprint_gVar(){printf("%d\n",gVar);}下面是test.cpp的代码。#include__threadintgVar;void__attribute__((weak))print_gVar();intmain(){gVar=10;print_gVar();return0;}然后我使用以下脚本来编译和运行它们。g++