This article describes a method for “reconnecting” the separate paths of an EV3 program after a task split. It’s usually best to avoid task splits where possible, especially because of the risk of them leading to a “race condition” (more of this later in a separate post) but sometimes they’re hard to avoid.
Let’s say we want to run two motors independently and then stop each one in response to a particular EV3 button. In this example, Motor A will run until the Left EV3 button is pressed and, at the same time, Motor D will run until the Right EV3 button is pressed. The task split provides a simple way of setting this up so that the motors can be turned off in either order.
What if we want to continue the program after both motors have been turned off, but still allow for them to be turned off in either order? For example, how could we modify the previous example so that the cheering sound is played only after both task have completed?
Maybe it would be nice if we could somehow reconnect the tasks with something like the opposite of a task split, but the EV3 Software doesn’t allow us to do that…. or at least not directly!
A relatively simple workaround is to use a “flag”. That is, we create a logic variable and set it to false prior to the task split, then set it to true at the end of the forked task. Then have the main task wait until the flag is set to true before continuing.
Furthermore, by creating additional logic variables to serve as additional flags and the use of a Logic Operations block in the wait loop, this idea could be extended to accommodate multiple task splits.