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.

Execution scheduling: C++ demo

Execution scheduling: C++ demo - C++ Tutorial

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

Start my 1-month free trial

Execution scheduling: C++ demo

- [Olivia] To demonstrate how scheduling can impact execution, we've written the C++ program that executes two threads named Barron and Olivia, that continuously traps vegetables for about one second. The vegetable chopper function on line nine, takes in a string argument for a name of which can be used to uniquely identify this thread. The function begins by initializing a local variable on line 10 to count the number of vegetables this thread chops. The while loop on line 11 will execute as long as the Boolean chopping variable that we initialized on line seven is true. And with each loop iteration, it increments the value of the local vegetable count variable. Finally, after the while loop finishes, the vegetable chopper function prints out how many total vegetables it chopped on line 14. Down in the main function on lines 18 and 19, we create two threads to execute the vegetable chopper function and pass in…

Contents