为什么没有超载Interlocked.Add的接受双打作为参数? [英] Why is there no overload of Interlocked.Add that accepts Doubles as parameters?

查看:136
本文介绍了为什么没有超载Interlocked.Add的接受双打作为参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全AP preciate的Threading.Interlocked类提供的原子;我不明白,不过,为什么添加功能只提供了两个重载:一个是整数,另一个为多头。为什么不双打,或任何其他数值类型为此事?

I fully appreciate the atomicity that the Threading.Interlocked class provides; I don't understand, though, why the Add function only offers two overloads: one for Integers, another for Longs. Why not Doubles, or any other numeric type for that matter?

显然,改变双重预期的方法是CompareExchange;我猜这是因为修改双是一个比较复杂的操作比修改一个整数。不过目前尚不清楚我为什么,如果CompareExchange和添加既可以接受整数,他们也无法接受这两个双打。

Clearly, the intended method for changing a Double is CompareExchange; I am GUESSING this is because modifying a Double is a more complex operation than modifying an Integer. Still it isn't clear to me why, if CompareExchange and Add can both accept Integers, they can't also both accept Doubles.

推荐答案

围绕Windows的API互锁互锁类包装**功能。

The Interlocked class wraps around the Windows API Interlocked** functions.

这些都是反过来,缠绕机处理器的API,使用LOCK指令preFIX为86。它仅支持prefixing以下说明:

These are, in turn, wrapping around the native processor API, using the LOCK instruction prefix for x86. It only supports prefixing the following instructions:

BT,BTS,BTR,BTC,XCHG,XADD,添加或,ADC,SBB,AND,SUB,XOR,NOT,NEG,INC,DEC

BT, BTS, BTR, BTC, XCHG, XADD, ADD, OR, ADC, SBB, AND, SUB, XOR, NOT, NEG, INC, DEC

您会注意到这些,反过来,pretty的多少映射到互锁方法。不幸的是,在此不支持的ADD功能用于非整数类型。添加64位多头上支持64位平台。

You'll note that these, in turn, pretty much map to the interlocked methods. Unfortunately, the ADD functions for non-integer types are not supported here. Add for 64bit longs is supported on 64bit platforms.

下面是一个伟大的文章的指令级讨论锁定语义。

Here's a great article discussing lock semantics on the instruction level.

这篇关于为什么没有超载Interlocked.Add的接受双打作为参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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