The second law of thermodynamics and stability