  Stacks of intrinsic Josephson junctions in the resistive state can by
efficiently synchronized by the internal cavity mode resonantly excited by the
Josephson oscillations. We study the stability of dynamic coherent states near
the resonance with respect to small perturbations. Three states are considered:
the homogeneous and alternating-kink states in zero magnetic field and the
homogeneous state in the magnetic field near the value corresponding to half
flux quantum per junction. We found two possible instabilities related to the
short-scale and long-scale perturbations. The homogeneous state in modulated
junction is typically unstable with respect to the short-scale alternating
phase deformations unless the Josephson current is completely suppressed in one
half of the stack. The kink state is stable with respect to such deformations
and homogeneous state in the magnetic field is only stable within a certain
range of frequencies and fields. Stability with respect to the long-range
deformations is controlled by resonance excitations of fast modes at finite
wave vectors and typically leads to unstable range of the wave-vectors. This
range shrinks with approaching the resonance and increasing the in-plane
dissipation. As a consequence, in finite-height stacks the stability frequency
range near the resonance increases with decreasing the height.
