Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Multithreading 如何使用g+在64位solaris sparc上编译线程本地存储(TLS)+;_Multithreading_Gcc_Sparc_Thread Local Storage - Fatal编程技术网

Multithreading 如何使用g+在64位solaris sparc上编译线程本地存储(TLS)+;

Multithreading 如何使用g+在64位solaris sparc上编译线程本地存储(TLS)+;,multithreading,gcc,sparc,thread-local-storage,Multithreading,Gcc,Sparc,Thread Local Storage,我有一段C/C++代码,它使用_thread关键字进行线程本地存储,但在64位Solaris Sparc和g++(版本4.0.2)上编译时遇到问题,而在linux和g++34编译器上编译并运行正常。下面是一个源代码示例: __thread int count = 0; “g++-dumpversion”命令中的编译器信息返回“4.0.2”,而“g++-dumpmachine”显示“sparc-sun-solaris2.8”uname-a“显示”SunOS devsol1 5.9通用_11855

我有一段C/C++代码,它使用_thread关键字进行线程本地存储,但在64位Solaris Sparc和g++(版本4.0.2)上编译时遇到问题,而在linux和g++34编译器上编译并运行正常。下面是一个源代码示例:

__thread int count = 0;
“g++-dumpversion”命令中的编译器信息返回“4.0.2”,而“g++-dumpmachine”显示“sparc-sun-solaris2.8”uname-a“显示”SunOS devsol1 5.9通用_118558-26 sun4u sparc SUNW,UltraAX-i2

使用g++运行make时的错误消息是:“错误:此目标不支持线程本地存储”,我使用的编译器选项是

 -m64    -g -fexceptions -fPIC     -I../fincad -I/usr/java_1.6.0_12/include -I/usr/java_1.6.0_12/include/solaris -I/opt/csw/gcc4/lib/sparcv9 -I/opt/csw/gcc4/lib/gcc/sparc-sun-solaris2.8/4.0.2/sparcv9 -I. -I/usr/include -I/usr/include/iso -I/usr/local/include
任何帮助都是非常感谢的,因为我已经在这个周末挣扎了,并且面临着最后期限

谢谢,
Charles

您可以使用以便携方式实现此功能


如果没有其他问题,您应该能够在Solaris上使用它作为参考来解决这一问题。

您可以忽略特定于gcc的线程存储,而使用特定于posix的AD存储。它应该工作,它不是gnu特定的。上面有一个例子

这里有一个来自的简明示例。显然,您需要使用多个线程

pthread_key_t   tlsKey = 0;

int main(int argc, char **argv)
  rc = pthread_key_create(&tlsKey, globalDestructor);
  /* The key can now be used from all threads */

  // Each thread can now use the key:
  char *myThreadDataStructure;
  void                 *global;

  myThreadDataStructure = malloc(15);//your data structure
  pthread_setspecific(tlsKey, myThreadDataStructure);   

  /* Get the data back */    

  global  = pthread_getspecific(tlsKey);


  free (myThreadDataStructure);
  rc = pthread_key_delete(tlsKey);
}

您可以尝试将
-pthread
命令行选项添加到g++:用GCC的说法,这个选项意味着:“完成POSIX线程支持所需的一切”。这可能会解除对
\u线程的支持


使用
\uuuu Thread
的线程本地存储需要编译器和链接器(编译结束时调用的静态链接器和执行程序时调用的动态链接器)中的某些特定系统支持。我不知道您的特定组合(一个相当旧的g++和一个相当旧的Solaris)是否受支持(一些谷歌搜索显示,有些人可以将它与一个较旧的gcc[3.4.3]和一个较新的Solaris[10])。如果不支持,可以使用POSIX/Single Unix函数
pthread\u key\u create()
pthread\u setspecific()
pthread\u getspecific()
。与传统TLS(几乎与访问标准全局/静态变量一样快)相比,
\u线程限定符稍慢,也不方便,但至少可以工作。

可以工作吗?
特定于线程的ptr
具有很高的价格标签。到目前为止,它工作得非常好,在linux和solaris 64位环境中。编译得像个符咒。仍在等待测试完成,但看起来很有希望。另一方面,posix thead专用存储与gnu的性能相比如何。在我的测试中,我没有注意到任何戏剧性的事情,但我对这方面很感兴趣。另一位评论员提到线程特定的ptr有明显的性能损失。老实说,我从来没有使用过gnu扩展。不过,我很想知道它是如何工作的。