Does pthread_cancel behave differently on hand and ppc?

I am currently working on a multi-threaded application that will be deployed on arm and ppc architectures. I have problems with pthread_cancel on my hand.

pthread_cancel on the hand does not behave the same with ppc. The thread is canceled, but the destructor of the local thread variable is not called on the hand. I also tried to explicitly define the undo cleanup handler procedure set via pthread_cleanup_push. But it is not called when the thread is canceled.

The code works fine with ppc. When a thread is canceled, a local variable destructor is called. And when I explicitly defined the cleanup handler, it was called and executed when pthread_cancel was called.

Am I missing something? Perhaps some compiler options?

  • Programming Language: C ++
  • Compiled by: arm-linux-g ++ / powerpc-linux-g ++
  • OS: Linux

EDIT:

I found a similar problem registered in this libc error .

Using gcc instead of g ++ and adding the -fno-exception option to the compiler did the trick. But I really want to understand the essence of this problem. Also, the -fno-exception exception means that I will not be able to handle exception handling in my application, and not that I am using it now, but I could be in the future.

Thanks.

+5
source share
1 answer

Canceling a theme without the help of an application is a bad idea. Just google . It is much better to tell the thread to end itself by setting a flag variable, which is periodically checked by the thread.

, ++ 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();
};
+2

All Articles