简体   繁体   English

在gcc 3.4.3中使用原子操作

[英]Using atomic operations in gcc 3.4.3

The built in atomic operations were introduced in gcc-4.1.2. 内置的原子操作在gcc-4.1.2中引入。 However, I am using gcc on OpenIndiana which only has gcc 3.4.3. 但是,我在只有gcc 3.4.3的OpenIndiana上使用gcc。 Now my question is how to use atomic operations in gcc 3.4.3? 现在我的问题是如何在gcc 3.4.3中使用原子操作? Moreover I have tried to use gcc 4.6.1 in OpenIndiana but it doesnt work, as it complains about some runtime libraries. 此外,我尝试在OpenIndiana中使用gcc 4.6.1,但是它不起作用,因为它抱怨某些运行时库。 If anyone has successfully used it, kindly let me know. 如果有人成功使用了它,请告诉我。

I would suggest you to upgrade your GCC compiler. 我建议您升级GCC编译器。 A GCC 3 is an ancient thing. GCC 3是古老的东西。

If you cannot install a newer version of GCC, you should try compiling a GCC 4.6.1 compiler from its source code. 如果无法安装较新版本的GCC,则应尝试从其源代码编译GCC 4.6.1编译器。 (don't forget to compile it in a build tree outside of the source tree, and don't forget all the dependencies). (不要忘记在源代码树之外的构建树中进行编译,也不要忘记所有依赖项)。

You did not mention or explained why your compilation of GCC 4.6.1 failed. 您没有提到或解释GCC 4.6.1编译失败的原因。 What runtime libraries did it complain about? 它抱怨什么运行库? Did you run ldconfig after installing it? 安装后是否运行了ldconfig

GCC has great inline assembly support, so you could just use __asm to make your own variant of the various atomic ops. GCC具有出色的内联汇编支持,因此您可以使用__asm制作各种原子操作的自己的变体。 It'll be specific to your target platform however, so you'll need some good macros to switch to the right versions. 但是,它将特定于您的目标平台,因此您需要一些良好的宏才能切换到正确的版本。

To add to existing answers - have you looked at Spec Files Extra Repository ? 要添加到现有答案中,您是否看过Spec Files Extra Repository I never used it myself but it seems like it offers gcc 4.6 compiler package. 我自己从未使用过它,但似乎它提供了gcc 4.6编译器软件包。

On Solaris, the alternative could be to fall back to libc atomic_ops(3C) interfaces. 在Solaris上,替代方法可能是回退到libc atomic_ops(3C)接口。 These might or might not get inlined, but they're guaranteed always available (and always behave in the same way) no matter which compiler you use. 它们可能会内联,也可能不会内联,但是无论您使用哪个编译器,都可以保证它们始终可用(并且始终以相同的方式运行)。

Beyond that, I second the suggestion to either upgrade your gcc, and/or to get the SunStudio 12.2 compilers (they're royalty-free; even if you only use it for testing, code quality tends to go up if it's made to work with more than one compiler ...). 除此之外,我还建议您升级gcc和/或获得SunStudio 12.2编译器 (它们是免版税的;即使您仅将其用于测试,如果能够正常工作,代码质量也往往会提高)与多个编译器...)。 Yes, it'll install/run on OpenSolaris-based distributions as well. 是的,它还将在基于OpenSolaris的发行版上安装/运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM