InterlockedIncrement, InterlockedCompareExchange, etc
Jack Applegame via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Aug 28 14:47:35 PDT 2016
On Sunday, 28 August 2016 at 20:38:30 UTC, Lodovico Giaretta
wrote:
> On Sunday, 28 August 2016 at 19:53:51 UTC, Illuminati wrote:
>> What are the D equivalents to these types of functions?
>>
>> I do not see anything in core.atomic that can accomplish this.
>> I have tried to include core.sys.windows.winbase but still get
>> linker errors(I've also directly tried importing kernel32
>> using various methods and still nothing). Regardless, would be
>> nicer to have a more portable solution.
>
> I'm not an expert in this field (so probably I'm missing
> something), but I would think that InterlockedIncrement could
> be done with atomicOp!"+"(val, 1) and
> InterlockedCompareExchange with cas.
Exactly!
InterlockedIncrement - atomicOp!"+="(val, 1) or
val.atomicOp!"+="(1)
InterlockedCompareExchange - cas
More information about the Digitalmars-d-learn
mailing list