In a more detailed design, you would have every train publish a "movement plan" every few milliseconds. The plan contains the current location (with uncertainty bounds), and future locations. The plan also contains alternate future locations that could happen in various emergency or failure situations - and one of those is to apply the emergency brakes.
A system checks each plan against the plans of all other trains, and approves them if they are non-colliding. The 'alternate' plans can overlap only if to do so indicates independant failures must have occurred - for example the brakes of train 1 fail at the same time as the traction motor of train 2 gets stuck on max, and comms fail.
Track infrastructure such as signals and points would also submit plans - so that for example a set of points can prevent any trains passing over while it isn't in a safe locked state.
All trains must then follow one of the plans they have approved. If comms fail and they can't get a new plan approved, they must still follow an approved plan - which means they are guaranteed not to collide with any other train.
All plans would be signed with timestamps (to prevent someone maliciously changing them to cause an accident), and would normally be delivered by dedicated rail infrastructure, but could be delivered by 3g/4g/wifi in an emergency. Manual plans could also be entered and distributed, for example via USB stick, for maintenance - such plans would say "I have access to this huge segment of track, and nobody else may enter".