本文介绍了C#多线程无符号增量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
欲增加从多个线程无符号整数。
I want to increment an unsigned integer from multiple threads.
我知道Interlocked.Increment,但它不处理无符号整数。我可以使用锁(),但我宁愿不如果可能出于性能的考虑。
I know about Interlocked.Increment, but it does not handle unsigned integers. I could use lock(), but I would rather not if possible for performance reasons.
时的线程安全只是为了增加它以正常的方式?它不会重要,如果偶尔增量迷路了,因为它只是用于统计。我不希望是让损坏的价值。
Is it thread safe just to increment it in the normal way? It would not matter if the occasional increment got lost, as it's only used for statistics. What I don't want is the value to get corrupted.
推荐答案
您可以声明UINT为volatile。
you can declare the uint as volatile.
的
这篇关于C#多线程无符号增量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!