A diver doesn't just "run out of air". A diver gets low on gas because they failed to look at their gauges, and/or didn't plan properly.
It can happen that you get a free flow on your regulator, inflator, valve or manifold, but none of these make you run out of gas immediately. You have time to swim to a team mate and breathe from their regulator (if you are on a single cylinder and can't close any valves).
If you have a valve rolling-shut (implying you're on a twinset), you _will_ run out of air until you open it again, and you would be trained to calmly open it, or just switch to your secondary regulator.
Running out of gas can be prevented by planning the dive and keeping an eye on your gauge, depth and timer.