When I kill a pThread in C++, do destructors of objects on stacks get called?

后端 未结 4 1043
悲&欢浪女
悲&欢浪女 2021-01-02 01:54

I\'m writing a multi-threaded C++ program. I plan on killing threads. However, I am also using a ref-counted GC. I\'m wondering if stack allocated objects get destructed whe

4条回答
  •  爱一瞬间的悲伤
    2021-01-02 02:28

    It's not standardised to do this. It appears that some implementations do and some don't.

    pthread_cancel() really should be avoided, if you can; it doesn't actually stop the thread until it hits a cancellation point, which is usually any other pthread_* call. In particular, on lots of platforms a cancel won't interrupt a blocking read.

提交回复
热议问题