pthread_cancel 在arm 和ppc 上的行为不同?

发布于 2024-07-15 02:51:41 字数 753 浏览 1 评论 0原文

我目前正在开发一个多线程应用程序,该应用程序将部署在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

策马西风 2024-07-22 02:51:41

在没有应用程序帮助的情况下取消线程是一个坏主意。 只需 Google。 最好通过设置由线程定期检查的标志变量来告诉线程自行结束。

实际上取消非常困难,以至于在最新的 C++0x 草案中已将其省略。 您可以搜索 http://www.open -std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html 并且根本找不到任何取消的提及。 这是建议的线程类的定义(在那里你找不到取消):

class thread
{
public:
    // types:
    class id;
    typedef implementation-defined native_handle_type; // See [thread.native]

    // construct/copy/destroy:
    thread();
    template <class F> explicit thread(F f);
    template <class F, class ...Args> thread(F&& f, Args&&... args);
    ~thread();
    thread(const thread&) = delete;
    thread(thread&&);
    thread& operator=(const thread&) = delete;
    thread& operator=(thread&&);

    // members:
    void swap(thread&&);
    bool joinable() const;
    void join();
    void detach();
    id get_id() const;
    native_handle_type native_handle(); // See [thread.native]

    // static members:
    static unsigned hardware_concurrency();
};

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):

class thread
{
public:
    // types:
    class id;
    typedef implementation-defined native_handle_type; // See [thread.native]

    // construct/copy/destroy:
    thread();
    template <class F> explicit thread(F f);
    template <class F, class ...Args> thread(F&& f, Args&&... args);
    ~thread();
    thread(const thread&) = delete;
    thread(thread&&);
    thread& operator=(const thread&) = delete;
    thread& operator=(thread&&);

    // members:
    void swap(thread&&);
    bool joinable() const;
    void join();
    void detach();
    id get_id() const;
    native_handle_type native_handle(); // See [thread.native]

    // static members:
    static unsigned hardware_concurrency();
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文