Atomic bit operation

      The arguments to the operation function are a pointer and a tag

 

Atomic bit operations are defined in the file . It's strange that bit manipulation functions operate on ordinary memory addresses . Atomic bit operations are, in most cases, memory access to a word length , Therefore, the tag number should be located in 0-31 between ( stay 64 It's on a bit machine 0-63 between ), But there is no limit to the range of tags .

 

Some functions of bit operation in atomic operation are as follows :
void set_bit(int nr, void *addr)        Atomic settings addr Reference to nr position
void clear_bit(int nr, void *addr)      The first order of the object referred to by the atomic emptying nr position
void change_bit(nr, void *addr)         Atom flip addr Reference to nr position
int test_bit(nr, void *addr)            Return of atoms addr Bit referred object nr position
int test_and_set_bit(nr, void *addr)    Atomic settings addr Of the object referred to nr position , And return the original value
int test_and_clear_bit(nr, void *addr)  Atomic emptying addr Of the object referred to nr position , And return the original value
int test_and_change_bit(nr, void *addr)  Atom flip addr Of the object referred to nr position , And return the original value

 

    unsigned long word = 0;

    set_bit(0, &word); /* The first 0 Bit is set */

    set_bit(1, &word); /* The first 1 Bit is set */

    clear_bit(1, &word); /* The first 1 Bit cleared */

    change_bit(0, &word); /* Flip page 0 position */

 

 

Technology
©2019-2020 Toolsou All rights reserved,
( Essence )2020 year 6 month 29 day C# Class library Interface signature verification PHP Printout log@Repository The role of annotations Java Thread of Sleep() Summary of usage pytorch of ResNet18( Yes cifar10 The accuracy of data classification is achieved 94%)java Compile time and runtime exceptions in golang One line of code converts the slice into a semicolon separated string Cheats developers apologize TypeScript Data types in is enough Online troubleshooting HTTP Status code ——415 and 406