# interlocked\_compare\_exchange

### Function

> interlocked\_compare\_exchange

### Syntax

> interlocked\_compare\_exchange( \*Variable, Expression, Expression );

### Parameters

**\[\*Variable (Destination)]**

A reference to a variable (most of the time a global variable) that is compared with the value of **Comperand**.

**\[Expression (ExChange)]**

Specifies the output value pointed to by **Destination** if the input value pointed to by **Destination** equals the value of **Comperand**.

**\[Expression (Comperand)]**

Specifies the value that is compared with the input value pointed to by **Destination**.

### Description

Performs an atomic operation that compares the input value pointed to by **Destination** with the value of **Comperand**. If **Comperand** is equal to **Destination**, then **Destination** is set to equal **Exchange**. Otherwise, **Destination** is unchanged.

### Return value

The function returns the original value of **\*Destination**.

### Examples

None

### Remarks

None

### Related

[interlocked\_exchange\_add](https://docs.hyperdbg.org/commands/scripting-language/functions/interlocked/interlocked_exchange_add)

[interlocked\_increment](https://docs.hyperdbg.org/commands/scripting-language/functions/interlocked/interlocked_increment)

[interlocked\_exchange](https://docs.hyperdbg.org/commands/scripting-language/functions/interlocked/interlocked_exchange)

[interlocked\_decrement](https://docs.hyperdbg.org/commands/scripting-language/functions/interlocked/interlocked_decrement)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hyperdbg.org/commands/scripting-language/functions/interlocked/interlocked_compare_exchange.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
