Of two locomotives you'll always have one that is slightly slower due to differences in the motors and other factors.
Many model railroad companies are producing locomotives with DCC (Digital Command Control). This allows for constant track power (good for powering accessories), then digital signals are sent through the rails and decoded in chips on the locomotive to tell it how fast to go.
One benefit is that you can instruct two locomotives to travel at the same speed.
Another benefit is that trains with two-rail track can now navigate reverse loops without causing a short circuit.
Theoretically someone could modify a Lego locomotive to use DCC (Atlas sells relatively inexpensive kits) that might work on a Lego train. Hopefully future Lego trains will have DCC - especially as their popularity increases and track plans start to require it.
With DCC, you can even run two trains in opposite directions on the same track.