Producer-consumer working for N iteractions.