This is one of the 20 required skills for PADI OW certification. It is an easy one to forget, because you (hopefully!) don't find yourself in situations that require it too often. Putting your thumb over the mouthpiece of a freeflowing reg will do nothing; the air will just exit the exhaust valve instead of the mouthpiece. If your octo is not freeflowing, switching to it is an appropriate response, but you'll still have to consider the issue of quick air depletion. If the cause of the freeflow is in the 1st stage, (it often is) then the octo is also likely to start flowing, sometimes followed by the LP inflator hose. If I were at depth and both my 2nd stages started flowing, I would quickly disconnect the LP inflator hose to prevent a possible uncontrollable BC inflation and resulting express trip to the surface.
The way we demonstrated this skill in OW classes is: take the reg out of your mouth, then bite down on one wing or tab, leaving the other outside your mouth. Tip your head so that that side is up (it helps keep the bubbles out of your face a little) then press the purge and get used to taking what air you need. It's very easy, although it can be a little scary with all the bubbles. One improvement in terms of realism for practicing would be to initiate the freeflow while the reg is still in your mouth, then adjust to it rather than getting the reg placed just right and then starting the flow.