How many threads in minimum will be required for developing a traffic signal application?
I think it is only one, because when any one of the lights is in green the other 3 directions will be red. And for this application there is no need for multiple operations to be run parallel y.
How many threads in minimum will be required for developing a traffic signal application?
Share
As a driver, I sure hope it’s only one thread!
You would only need one thread, but imagine the implications of non-threadsafe code or threading bugs…
someone could literally die!
Edited
Actually, "it depends" is the correct answer, if there is one.
Simple traffic lights, for example pedestrian crossings, could simply block waiting for a button press then complete the cycle and return to a blocking wait again.
Complex event-driven lights that can receive many inputs, may need multiple threads if the hardware doesn’t support interrupts or other single threaded mechanisms for dealing with real time input signals.