i**p 发帖数: 902 | 1 In java, the daemon thread will be abort once all user (non-daemon) threads
exit.
How about pthread in linux? I don't remember pthread has the same concept.
It calls detached, right?
Another deference is detached thread is not abort after all the joinable or
calling thread is done, so that the process is still running. Right?
How is standardized C++ thread defined?
Please commend |
p***o 发帖数: 1252 | 2 All of them are "daemon" in the sense if main() returns then the program
exits.
threads
or
【在 i**p 的大作中提到】 : In java, the daemon thread will be abort once all user (non-daemon) threads : exit. : How about pthread in linux? I don't remember pthread has the same concept. : It calls detached, right? : Another deference is detached thread is not abort after all the joinable or : calling thread is done, so that the process is still running. Right? : How is standardized C++ thread defined? : Please commend
|
i**p 发帖数: 902 | 3 To make it more clear and less argument, I re-word my post.
In pthread on Linux,
main() {
...
pthread_create(A)
pthread_create(B) // need much more time to run than thread A does
pthread_detach(B) // B is detached
pthread_create(C) // need much more time to run than thread A does
// but neither joined nor detached
...
pthread_join(A) // #1
return // #2
}
My understanding is
1. main() will wait at #1 until thread A is done.
2. once return in #2 is called in main(), both thread B and C will be killed
. The process will not wait thread C returning though it is not detached.
【在 p***o 的大作中提到】 : All of them are "daemon" in the sense if main() returns then the program : exits. : : threads : or
|
z*y 发帖数: 1311 | 4
the
Thread is not process, how could a thread live if the process exits?
【在 i**p 的大作中提到】 : To make it more clear and less argument, I re-word my post. : In pthread on Linux, : main() { : ... : pthread_create(A) : pthread_create(B) // need much more time to run than thread A does : pthread_detach(B) // B is detached : pthread_create(C) // need much more time to run than thread A does : // but neither joined nor detached : ...
|
i**p 发帖数: 902 | 5 My point is the process may NOT exit though main() reaches to the end of
function because other threads are running.
On the other hand, main() is started from a thread. It is POSSIBLE to
implement a system to keep the process running until all the threads exit.
【在 z*y 的大作中提到】 : : the : Thread is not process, how could a thread live if the process exits?
|
z*y 发帖数: 1311 | 6 I don't think so. My feeling is that all threads will get killed once main
exits, doesn't matter detach or not.
But I could be wrong.
Why not just write some small testing code?
In case you have interesting findings, I would like to learn. |