A physical mechanism for the production of solar flares