Switch to a proper round robin thread scheduler.

Fixes #328.