Terrorist Acts/Mass Killings:
How do you prevent them? By having good intel and acting on that intel. Having intel can mean "seeing and noting the warning signs and then acting on that information"...whether it's a terrorist cell planning and preparing for an attack or a couple of kids with emotional problems who show the intent to act on their feelings.
How do you stop or impede an attack, regardless of the motivation of the attacker(s)? By having the capability and being in place to use that capability. Since the Israelis keep being brought up, let's use them as an example. The civilian population is generally armed...not all, but to a much higher percentage than Concealed Handgun Permit holders in the States. And not just limited to handguns. Long guns are common.
Why do you suppose this is? Because acts of terrorism have happened frequently in many parts of the country (less so since the wall went up...but it could flare up at any time) and the people need the ability and the means to stop an act that is occuring.
The original poster has a valid question.