简体   繁体   中英

PThread monitoring

How does one get the status of a Pthread and what would be a good way to monitor the threads statuses continuously so that if anything goes wrong I can kill the other threads that are linked?

I have two threads, one depends on the constant calculation result and I want to monitor the threads and kill a thread which might end up running alone.

What is a good way of doing this?

How about a heartbeat?

I found your question looking for a similar answer, and I have not found a way to detect pthread exits from another thread.

Assuming we don't get a better answer to this question, Here is my solution: My threads are rather predictable so I am having them set a volatile bool when they error out or exit that will be acted on by a watchdog running in my main thread to communicate that event to the remaining threads.

Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM