Fixed possible concurrency issue when iterating over the list of
producers and consumers