... continued
This lesson continues the discussion on the use of condition variables in Ruby.
We'll cover the following...
As an illustration of the importance of the pattern to use when working with condition variables, we'll rewrite our
ping-pong program to print ping and pong on the console alternatively. Instead of having two blocks, we'll have a single block of code that prints the two strings. That is we don't have separate code blocks, one to print each string. We'll create ten threads that execute the same code snippet and print ping or pong based on the value of the boolean flag
variable. We also introduce an additional variable active
that is used to gate entry into the critical section of the code
implicitly.
We have taken a departure from the idiomatic use of condition variables and used an if
condition instead of a while
.
Take a ...