A multithreaded generalized producer/consumer