生产者消费者
我有一个应用程序,其中有一部分以非常高的频率写入和读取一些变量。 是否需要信号量或锁(在这种情况下数据一致性不是问题)。应用程序是否有可能终止或崩溃。我不想进入线程、信号量和其他东西,因为它是应用程序的一个微不足道的部分。
i have an application which has a part where some variables are written and read at very high frequency.
Is there any need of a semaphores or locks(Data consistency is not a concern in this case).Is there any chance of application terminating or crashing.I dont want to get into threads,semaphores and stuff as it is a trivial part of application.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题中没有足够的信息来为您提供准确的答案,但一般来说 - 如果您有多个线程,一个线程生成数据,一个线程消耗数据,那么是的,您将需要同步。
您可以使用 BlockingQueue,或者只是一个简单的同步对象,只要适合您的情况...但是您将需要一些同步,否则您将面临随机难以重现崩溃的风险。
在处理现在变得流行的多核系统时,这一点更为重要。
There is not nearly enough information in your question to give you an accurate answer, but in general - if you have multiple threads, and one produces data, one consumes it, then yes, you will need synchronization.
You could use a
BlockingQueue
, or just a simple synchronized object, whatever is appropriate in your case... but you will need some synchronization, or else you risk random hard-to-reproduce crashes.This is even more important when dealing with multi-core systems, which are becoming popular now.