From the course: Parallel and Concurrent Programming with C++ Part 1

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Detached thread

Detached thread - C++ Tutorial

From the course: Parallel and Concurrent Programming with C++ Part 1

Start my 1-month free trial

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 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. - While I try to reclaim some memory, or counter space by clearing out Barron'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…

Contents