boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - Daemon thread
相关主题
Windows Thread API
pthread and C++
有专门介绍multithreading编程的书吗
多线程 编程,process 和 thread 的一些问题。
how many ways in C++ to release a mutex?
C++11 native thread问题
c++11 std thread类 怎么样,大家用过么
我写的C++ ParallelForLoop,感兴趣的来下载测试
这年头是不是只有做网站
怎么练习multi-threading,平常工作都是用Java框架
相关话题的讨论汇总
话题: thread话题: pthread话题: daemon话题: detached话题: threads
进入Programming版参与讨论
1 (共1页)
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.
1 (共1页)
进入Programming版参与讨论
相关主题
怎么练习multi-threading,平常工作都是用Java框架
怎么练习C++ multi-threading?
一直没有很好理解thread join itself,哪位解惑一下 (转载)
关于valgrind 的一个问题
重复利用threads的问题
Linux thread和NPTL thread什么关系? (转载)
如何强制thread和cpu绑定?
how to debug multi-thread program?
怎么 kill 一个 thread 啊
关于thread的stack
相关话题的讨论汇总
话题: thread话题: pthread话题: daemon话题: detached话题: threads