Make threadpool size a template parameter so we get rid of an expensive modulo op;
also implement the pos_read/written increment correctly.