pthread_cancel 在arm 和ppc 上的行为不同?
我目前正在开发一个多线程应用程序,该应用程序将部署在arm和ppc架构上。 我在手臂上使用 pthread_cancel 时遇到一些问题。
arm 上的 pthread_cancel 与 ppc 上的行为不同。 线程被取消,但线程局部变量的析构函数没有在arm 上调用。 我还尝试显式定义通过 pthread_cleanup_push 安装的取消清理处理程序例程。 但当线程被取消时,它不会被调用。
该代码在 ppc 上运行良好。 当线程被取消时,局部变量的析构函数被调用。 当我显式定义一个清理处理程序时,它会在调用 pthread_cancel 时被调用并执行。
我错过了什么吗? 也许有一些编译器选项?
- 编程语言:C++
- 编译器:arm-linux-g++/powerpc-linux-g++
- 操作系统:Linux
编辑:
我发现在此记录了类似的问题 libc 错误。
使用 gcc 而不是 g++ 并添加 -fno-exception 编译器选项就达到了目的。 但我真的很想了解这个问题背后的东西。 此外, -fno-exception 意味着我将无法在我的应用程序中执行异常处理,不是我现在正在使用它,而是我将来可能会使用它。
谢谢。
I'm currently working on a multi-threaded application that would be deployed on arm and ppc architecture. I'm having some problem with pthread_cancel on arm.
pthread_cancel on arm doesn't behave the same with ppc. The thread gets cancelled but the destructor for the thread's local variable isn't being called on arm. I also tried explicitly defining a cancellation cleanup handler routine installed via pthread_cleanup_push. But it isn't being called when the thread is cancelled.
The code works fine with ppc. When a thread is cancelled, local variable's destructor is being called. And when I explicitly defined a cleanup handler, it was called and executed when pthread_cancel was called.
Am I missing something? Some compiler options perhaps?
- Programming Language: C++
- Compilers: arm-linux-g++/powerpc-linux-g++
- OS: Linux
EDIT:
I have found a sort of similar problem logged on this libc bug.
Using gcc instead of g++ and adding -fno-exception compiler option did the trick. But I really want to understand stuff behind this issue. Moreover, the -fno-exception means I won't be able to perform exception handling in my application, not that I'm using it now but I might be in the future.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在没有应用程序帮助的情况下取消线程是一个坏主意。 只需 Google。 最好通过设置由线程定期检查的标志变量来告诉线程自行结束。
实际上取消非常困难,以至于在最新的 C++0x 草案中已将其省略。 您可以搜索 http://www.open -std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html 并且根本找不到任何取消的提及。 这是建议的线程类的定义(在那里你找不到取消):
Thread cancellation without the help from the application is a bad idea. Just google. It is much better to tell the thread to end itself by setting a flag variable that is periodically checked by the thread.
Actually cancellation is so hard that it has been omitted from the latest C++0x draft. You can search http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html and won't find any mention of cancellation at all. Here's the definition of the proposed thread class (you won't find cancel there):