The coherent spin dynamics of resident carriers, electrons, and holes in semiconductor nanostructures is studied theoretically under the conditions of periodical optical excitation using short laser pulses and in an external magnetic field. The generation and dephasing of spin polarization in an ensemble of carrier spins, for which the relaxation time of individual spins exceeds the repetition period of the laser pulses, are analyzed. Accumulation of the spin polarization is manifested either as resonant spin amplification or as mode locking of carrier spin coherences. It is shown that both regimes have the same origin, while their appearance is determined by the optical pump power and the spread of spin precession frequencies in the ensemble.