The year is 1894. You are designing a train system for a large city. Your boss informs you that the mayor’s office wants assurances that trains can’t have wrecks. The system will start small, but it is going to get big and complex over time with tracks crossing and switching. Remember, it is 1894, so computing and wireless tech are barely science fiction at this point. The answer — at least for the New York City subway system — is a clever system of signals and interlocks that make great use of the technology of the day. Bernard S. Greenberg does a great job of describing the system in great detail.
The subway began operation in 1904, well over 30 years since the above-ground trains began running. A clever system of signals and the tracks themselves worked together with some mechanical devices to make the subway very safe. Even if you tried to run two trains together, the safety systems would prevent it.
On the face of it, the system is very simple. There are lights that show red, yellow, and green. If you drive, you know what these mean. But what’s really interesting is the scheme used at the time to make them light.