This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Keeping a sub-thread alive  RSS feed

 
sidhu singh
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating a new thread inside my main thread. How can I keep this new thread alive for ever or for that matter for some limited time (even efter it finishes the processing)?
main{
.
.
new thread(); // keeping this thread alive
// even after it finishes processing
.
.
}
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The new thread will keep running (assuming you are running a loop inside it) after the main thread finishes. This is the default behavior. In fact, if you DONT want the thread to continue running after main() exits, you must explicitly set the thread to be a daemon thread before you start it.
So you don't have to do anything special to get the behavior you want. Try a simple example for yourself and see!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!