简体   繁体   English

如果实施生产者/消费者模型,则要使用的最佳数据结构是什么?

[英]If implementation a producer/consumer model, what's the best data structure to use?

I thought a queue should be OK, the producer push back and the consumer take from front. 我认为队列应该可以,生产商后退,而消费者则从前走。 Is there any other thoughts like thread safety etc? 还有线程安全等其他想法吗?

If you are using a queue inside of a multithreaded environment, I suggest a ConcurrentLinkedQueue . 如果您在多线程环境中使用队列,建议使用ConcurrentLinkedQueue This will manage all the synchronization for you. 这将为您管理所有同步。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM