Atomic bitfield operations on 80x86?
Does 80x86 have instructi开发者_运维百科ons for atomically testing and setting individual bits of a word?
If you mean testing and modifying a bit as a single atomic operation, then the bit test instructions (BT, BTS, BTR, and BTC) can all be made atomic by using the LOCK prefix.
If you mean testing a bit atomically, and then setting a bit atomically as separate operations, you can test the bit using a standard atomic read, and modifying the bit can be done using LOCK OR, LOCK AND, LOCK XOR instructions.
If you need something more complicated, e.g. testing one bit and then setting a different bit, you'll have to use the standard compare-and-swap CMPXCHG instruction in a retry loop.
精彩评论