Click here to Skip to main content
15,889,315 members
Please Sign up or sign in to vote.
3.77/5 (4 votes)
See more:
My own tests, as well as numerous web sources, show that all detached child threads die when the main thread exits or is killed (unless it exits with pthread_exit).
c - main thread exit, does other exit too? - Stack Overflow[^]

My question is, has this always been the specified behaviour? or could it have been different in old (10+ years) embedded Linux versions?

Thanks

PS
The reason for my asking is that I am digging into some legacy code that makes the opposite assumption. I want to know if the original writer was mistaken, or if I have missed something.


What I have tried:

I have not found anything an a (historically) different behavior.
Posted
Updated 10-Jan-17 22:49pm

1 solution

An interesting question. I have not a final answer but some hopefully useful information.

The actual behaviour is defined by the POSIX standard (and was so always).

But the Linux kernel uses a different thread model internally. So it had to be changed to provide full pthread compatibilty. See this PDF from 2002: POSIX Threads and the Linux Kernel[^].

The changes has been implemented with kernel version 2.6 (see Native POSIX Thread Library - Wikipedia[^]).

So older kernels used LinuxThreads - Wikipedia[^] which are not POSIX compatible and might behave differently regarding child threads (which did not exist with the LinuxThreads model that uses so called "tasks").
 
Share this answer
 
Comments
megaadam 10-Jan-17 8:45am    
Wow that was quick. Thanks! I will wait a day, before accepting, to see if more clever people have insights to share. :)
Jochen Arndt 10-Jan-17 8:53am    
You can accept multiple solutions and rate answers :)

But I understand that accepted questions might not get further answers.

A tip I forgot in my answer:
Check the kernel version that has been used with the old code (if possible).
If it was an old kernel, pthreads hasn't been used and the behaviour is defined by the used thread implementation.

Just recognised that someone has 1-voted your question.
I will counter that. I don't see any reason for a down vote.
megaadam 11-Jan-17 4:50am    
Thanks, even if it wasn't conclusive it was giving some insight.
The down-vote prolly came from someone with a "stackoverflowish mindset".
Albert Holguin 11-Jan-17 10:59am    
Yeah, it's actually a pretty good question. I'll upvote it as well (as well as your answer).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900