There are a ton of things, routing tables, signals, tickets. You can totally make sure a train doesn't enter a track if another train is on the track using signals and using tickets to route the various trains to different destinations based on color of train and what not.