Format
#include <builtin.h>unsigned int __smp_cmpxchg4(unsigned int *op1, unsigned int op2, unsigned int value)
Language Level: None
__smp_cmpxchg4 compares a 4 byte memory operand (*op1)
with a value (op2). If equal, op2 is stored
into *op1. The compare and exchange operation is atomic
even on multi-processor machines. This function will not work on
a 386 processor.
Return Value
The original value of the memory operand (*op1)
is returned.
Example
This example compares sem with sem_free,
determines they are equal, and exchanges the value of sem
and thread. It does all this atomically.
#include <stdio.h> #include <builtin.h>
const unsigned int sem_free = 0; unsigned int sem = 0; unsigned int thread = 1;
int main(void)
{
if (__smp_cmpxchg4(&sem, thread, sem_free) == sem_free)
{
printf("The exchange occurred.\n");
}
printf("sem = %u, thread = %u, sem_free = %u\n", sem, thread, sem_free);
/*****************************************
The output should be:
The exchange occurred.
sem = 1, thread = 1, sem_free = 0
*****************************************/
return 0; }
![]()
__cmpxchg4 -- Compare and
Exchange 4 Byte Values
__cmpxchg8 -- Compare and Exchange 8 Byte
Values
__smp_cmpxchg8 -- Compare and Exchange 8
Byte Values Atomically