How it works...

First, we set the number of runners to num_runners = 3 in order to set the final goal on the next line through the Barrier directive. The runners are set in the runners' list; each of them will have an arrival time that is determined in the runner function, using the randrange directive.

When a runner arrives at the finish line, call the wait method, which will block all the runners (the threads) that have made that call. The output for this is as follows:

START RACE!!!!
Dewey reached the barrier at: Sat Feb 2 21:44:48 2019

Huey reached the barrier at: Sat Feb 2 21:44:49 2019

Louie reached the barrier at: Sat Feb 2 21:44:50 2019

Race over!

In this case, Dewey won the race.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.184.214