Preguntas de entrevista para desarrollador compartidas por los candidatos
"When two trains approach each other at a crossing, both shall come to a full stop and neither shall start up again until the other has gone. Imagine a Java code with two process/instances of the same program Train.class What's the problem and how do you fix it."
It's a deadlock, solution is up to you.
Stupid answer. This doesn't even relate to a particular programming language. Everyone knows two "concurrent" threads can't get to the same execution point "at the same time". There will ALWAYS be an infinitesimal time difference of at least a tick at which point one will be able to take precedence and lock the other with whichever mechanism supported by the platform the programmer chooses, be it mutexes, critical sections, whatever. If you really answered that it just was a "deadlock", and still got hired, then that is proof of how easy is to get in.
To the person above me , it was never mentioned that both the trains arrive at the same time. It just says the train must come to a complete stop and wait for the other train to leave first. So yes it is a deadlock situation, and if you got hired I would be surprised !