Teaching mdworker some manners
You could throttle the specific program using AppPolice:

https://github.com/fuyu/AppPolice

However, this is usually the wrong way to go about it.

If programs using 100% CPU makes your computer shutdown, you have a hardware issue. It would be better to fix the hardware issue.

Usually a problem like the one you described means that the fans in your computer have stopped working to spec. They probably need to be cleaned or replaced.