From the course: Complete Guide to Parallel and Concurrent Programming with C++

Unlock this course with a free trial

Join today to access over 24,800 courses taught by industry experts.

Detached thread

Detached thread

- We often create threads to provide some sort of service or perform a periodic task in support of the main program. A common example of that is garbage collection. A garbage collector is a form of automatic memory management that runs in the background and attempts to reclaim garbage or memory that's no longer being used by the program. Many languages include garbage collection as a standard part of their runtime environment. But for this demonstration, I'll spawn my own new thread to handle garbage collection. - Man, what a mess. - Olivia is a separate child thread that will execute independently of my main thread so I can continue doing what I'm doing here, getting my soup ingredients ready. - Well, I try to reclaim some memory, or counter space, by clearing up Baron's garbage. - This setup with Olivia running as a separate thread to provide that garbage collection service will work fine until I'm ready to finish executing. Bam, now my soup spiced and ready. My main thread is done…

Contents