实时日期设置ReaderWriterLockSlim [英] Real Time Date Set ReaderWriterLockSlim

查看:76
本文介绍了实时日期设置ReaderWriterLockSlim的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个数据记录应用程序,该应用程序从多个来源获取数据并将其保存在数据集中.这是在线程中完成的.其他线程访问此数据,但没有一个更改.它只是每个来源的当前值.

另一个线程获取该数据并将其记录到另一个数据集中.这会每秒向数据集添加一行时间,并为每个值添加一列.其他线程也可以访问此数据,但从未更改.

我有几种形式可以访问两个数据集中的数据以进行实时查看.他们从不更改任何一个数据集中的数据.

如果只有一个线程在更改数据,是否需要使用读/写锁?我还没有看到没有使用锁的问题,但是当它等待访问数据集时,UI每秒都会出现延迟.谢谢.

I have developed a datalogging application that takes data from several sources and keeps them in a data set. This is done in a thread. Other threads access this data but none change it. Its just the current values from each source.

Another thread takes that data and logs it into another dataset. This adds a row to the data set each second with the time and a column for each value. This data is also accessed by other threads but never changed.

I have several forms that access the data in both datasets to view it in real time. They never change the data in either data set.

Do I need to use read/write locks if only one thread is changing the data? I haven''t seen a problem "yet" not using locks but I am seeing a delay on the UI every second when it waits for access to the datasets. Thanks.

推荐答案

显然,如果只有一个线程访问某些数据,则不需要锁定.
如果数据经常一次被一个线程以上读取,而写入却很少,则读取器/写入器锁定非常有效.然后已被读取的锁升级为写入;当没有线程正在写入时,它允许多个线程获得读取访问权限.如果不是这种情况,则最好使用简单锁定.

—SA
Apparently, if only one thread accesses some data, no lock is needed.

Reader/writer lock is very effective if the data is often read by more then one thread at a time, but more rarely written; then the lock already taken for read is upgraded to write; it allows several threads to get read access when no thread is writing. When it is not the case, simple lock is the best.

—SA


这篇关于实时日期设置ReaderWriterLockSlim的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆