www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Atomic bit operations

reply Crayo List <crayolist gmail.com> writes:
Are there atomic equivalents of bt(), btc(), bts(), btr() ... etc 
from core.bitop?

Thanks
Dec 10 2018
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Monday, 10 December 2018 at 23:20:22 UTC, Crayo List wrote:
 Are there atomic equivalents of bt(), btc(), bts(), btr() ... 
 etc from core.bitop?
Those are intrinsics that compile into a single cpu instruction, so they are probably already atomic...
Dec 10 2018
parent Crayo List <crayolist gmail.com> writes:
On Tuesday, 11 December 2018 at 01:37:25 UTC, Adam D. Ruppe wrote:
 On Monday, 10 December 2018 at 23:20:22 UTC, Crayo List wrote:
 Are there atomic equivalents of bt(), btc(), bts(), btr() ... 
 etc from core.bitop?
Those are intrinsics that compile into a single cpu instruction, so they are probably already atomic...
Thanks Adam, They need to be prefixed with 'lock' (on x86) in order to be atomic. That's what _interlockedbittestandset() on Windows does. And what this page says; https://www.felixcloutier.com/x86/LOCK.html It may be possible to implement using asm { }, but I was wondering if there wasn't something out there already doing it.
Dec 10 2018