Muscles are biological actuators extensively studied in the frame of Hill's classic empirical model as isolated biomechanical entities, which hardly applies to a living organism subjected to physiological and environmental constraints. Here we elucidate the overarching principle of a living muscle action for locomotion, considering it from the thermodynamic viewpoint as an assembly of actuators (muscle units) connected in parallel, operating via chemical-to-mechanical energy conversion under mixed (potential and flux) boundary conditions. Introducing the energy cost of effort as the generalization of the well-known oxygen cost of transport in the frame of our compact locally linear nonequilibrium thermodynamics model, we analyze oxygen consumption measurement data from a documented experiment on energy cost management and optimization by horses moving at three different gaits. Horses adapt to a particular gait by mobilizing a nearly constant number of muscle units minimizing waste production per unit distance covered; this number significantly changes during transition between gaits. The mechanical function of the animal is therefore determined both by its own thermodynamic characteristics and by the metabolic operating point of the locomotor system.