From Operation Lifesaver, I remember hearing the analogy that a fully loaded freight train hitting a car is roughly the equivalent of your vehicle hitting a coke can at 70mph. I haven't verified the math, but a 100+ car freight train weighs A LOT.
Also, never actually spent time behind the control stand, but I have been a life long railfan. First of all, someone above mentioned the 800 number posted at EVERY crossing. If you are stuck, use it. The more advance notice they have, the more likely they are to be able to stop.
Second, someone mentioned above their suspicious as to whether or not a train can "actually" stop that quickly. A couple of things:
Trains today(in the US) still operate on a variant of the over 100 year old Westinghouse air brake system. In this system, each car contains an air reservoir which is used to apply the brake shoes to the wheels. There is an air line running the entire length of the train that is controlled from the locomotive. When the pressure in the line(~90psi) is equal to the pressure inside the air tank on each car, the brakes are completely off. When the pressure in the line drops below the pressure in tank, the brakes are applied proportionally to the drop in pressure(and releasing works the opposite).
If the pressure in the brake line drops to zero, that signals an "emergency" application, which I believe on modern designs opens a secondary valve to speed the application of the brake shoes to the wheels and I seem to recall also taps a separate "emergency reservoir." This is something of a fail safe design, as if a train separates, for example, the separated cars will self-apply their brakes.
In any case, let's say the engineer seen an obstruction a few hundred feet ahead on the track. They throw the brake stand lever into "emergency", which promptly opens a valve to start releasing the pressure in the line. The problem is on a 100 car freight train, the brake line is over a mile long. As each car senses emergency, I THINK it also opens a valve that helps vent the line down to zero(don't hold me to that one) but it's going to take a LONG time for the emergency signal to propogate through brake line, then each car in turn to apply its brakes.
Once they're on, we have steel on steel, and very quickly the wheels can brake way and start sliding rather than turning. It's MUCH easier for this to happen than on asphalt with rubber tires.
That's not to mention-think of how many thousands of tons are behind that locomotive.
It doesn't matter how many tricks are used-that train is still going to take a long time to stop, and throwing it into emergency carries its own issues like the potential for derailment.