From the course: Parallel and Concurrent Programming with C++ Part 1
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Thread life cycle: C++ demo - C++ Tutorial
From the course: Parallel and Concurrent Programming with C++ Part 1
Thread life cycle: C++ demo
- [Instructor] To demonstrate the lifecycle of a thread from creation to termination, we've created this example program which recreates the interactions between Olivia and me, where I spawn her as a second thread to help slice sausages to make soup. The chef Olivia function defined on line seven begins by printing a message that Olivia has started and is waiting for the sausage to thought. The thread waits for three seconds, and then prints a second message that Olivia is done cutting sausage before it finishes execution. Below that, the program's main function represents my actions in the kitchen. It starts by printing a message on line 14 that Baron has started and requests Olivia's help, then creates a new chef Olivia object. In C++, a new thread will begin executing immediately after the associated thread object is instantiated. So, chef Olivia get started right away, pending the operating system schedule we're of…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.