C/++/# Kill all parents child threads from a child thread in C++

I have a C++ program that starts two threads from the parent thread, I need to kill both children from a child thread.

____> b
|
a -
|_____> c

I need to kill b & c from b. Issue is, I can't use simple flags, as c waits for input using cin.
Any help appreciated.
 

phyzguy

Science Advisor
4,206
1,191
Can't you pass a message back to a and have a kill both threads when it receives the message?
 

jim mcnamara

Mentor
3,525
1,736
You need the threadid of b and of c. Store them in global structure by parent as each thread is created. Then call pthread_kill() on each thread being sure to kill "yourself" last.

This is not greatr program design BTW. A better approach might be to send a SIGUSER1 from thread b to parent, and then have the parent call pthread_kill on everybody.
 

Want to reply to this thread?

"Kill all parents child threads from a child thread in C++" You must log in or register to reply here.

Related Threads for: Kill all parents child threads from a child thread in C++

  • Posted
Replies
8
Views
810
  • Posted
Replies
6
Views
8K
Replies
10
Views
683
N
Replies
2
Views
2K

Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving
Top