This site uses Akismet to reduce spam. Learn how your comment data is processed. If main function exits then all other threads will be exited. Create a Thread using Class in Python How to append text or lines to a file in python? Python: How to delete specific lines in a file in a memory-efficient way? Git : How to recursively add all files or folders to a repository? Python: Search strings in a file and get line numbers of lines containing the string Python: Three ways to check if a file is empty Python: Read a CSV file line by line with or without header Python: How to append a new row to an existing csv file?
Performance-wise, there's no difference between joinable threads vs detached threads. The only difference is that with detached threads, its resources such as thread stack and any associated heap memory, and so on - exactly what constitutes those "resources" are implementation-specific. Yes, it's legal to not join with a thread. But note that the threads created are joinable threads by default.
An example when you might want to join is when threads do a "piece" of work that's split between them. In that case, you'd want to check all threads complete before proceeding.
Task farm parallelism is a good example. Not necessary. But you'd often want to decide whether you want a joinable or detached thread at the time of creation.
Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Detached vs. Asked 11 years, 1 month ago. Active 1 year, 3 months ago. Viewed 39k times. Improve this question. Guy Avraham 2, 2 2 gold badges 33 33 silver badges 45 45 bronze badges. Add a comment. Active Oldest Votes. Improve this answer. Jonathan Leffler Jonathan Leffler k gold badges silver badges bronze badges.
I think this would terminate the process killing all the threads. So In what scenarios are detached threads used because I should be sure that detached thread has finished execution?
Ajax: Empirically, if the main thread finishes, the program exits and the threads are … terminated. That, at least, seems to be the behaviour on Mac OS X On a different note: Detachable threads are good for when you already have some other polling mechanism in place; you can use that same polling mechanism to check result state, and so know whether or not the thread completed.
It's a case of, "Is it ready? If so, use it. DareDevil: Yes, but…. You should be detaching the thread because you don't need to know the thread's return status and you don't need to know that it has finished, rather than because you might forget to join it.
0コメント