pthread_cancel在arm和ppc上表现不同?

gre*_*n_t 5 embedded arm pthreads

我目前正在开发一个可以部署在arm和ppc架构上的多线程应用程序.我手臂上的pthread_cancel有问题.

手臂上的pthread_cancel与ppc的行为不同.线程被取消但是没有在arm上调用线程局部变量的析构函数.我还尝试显式定义通过pthread_cleanup_push安装的取消清理处理程序例程.但是当线程被取消时它没有被调用.

该代码适用于ppc.取消线程时,正在调用局部变量的析构函数.当我明确定义一个清理处理程序时,它在调用pthread_cancel时被调用并执行.

我错过了什么吗?一些编译器选项也许?

  • 编程语言:C++
  • 编译器:arm-linux-g ++/powerpc-linux-g ++
  • 操作系统:Linux

编辑:

我发现在这个libc bug上记录了一些类似的问题.

使用gcc而不是g ++并添加-fno-exception编译器选项就可以了.但我真的想了解这个问题背后的原因.此外,-fno-exception意味着我将无法在我的应用程序中执行异常处理,而不是我现在正在使用它,但我可能在将来.

谢谢.

lot*_*har 3

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

实际上取消非常困难,以至于在最新的 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();
};
Run Code Online (Sandbox Code Playgroud)