Multithreaded producer/consumer implementation.