How to reconnect a task split

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.

Task split 1

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?

Task split 1a

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.

Task split 2 - flag demo

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.

Have fun!

The following two tabs change content below.

Rob Torok

I'm a teacher in Tasmania, Australia, and have been using LEGO MINDSTORMS with my students since 2001. I'm the editor in chief for LEGO Engineering (this site) as well as the content editor for LEGO Education Australia (

Latest posts by Rob Torok (see all)

2 thoughts on “How to reconnect a task split

  1. You do not need the flag.

    Delete the ‘Read Flag1 variable’ block inside the ‘loop 01’ block.
    Replace the ‘Write Flag1 variable’ block in the second task by a ‘Loop interrupt’ block.
    Then the ‘Write Flag1 variable’ block for initialization can also be deleted.
    This simplifies the program considerably.

    Both variants have one big issue: they busy wait (burning precious cycles and battery power).
    It would be better to actually block the task (like any wait block presumably does).
    In my variant this can be partially achieved by adding a ‘Wait 0.2s’ inside the ‘loop 01’ block.

    I also experimented by using ‘Reset timer’ in the second task and ‘Wait for timer <1' in the first but that has not yet lead to a nice solution.

Comments are closed.