extract producer-consumer pattern for parallel processing