Less hacky, configurable, way to limit threading

Change-Id: Iadd78ec6d71285c79f086601c46ffcfa5e3d9374