# interlocked\_exchange

### Function

> interlocked\_exchange

### Syntax

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

### Parameters

**\[\*Variable (Target)]**

A reference to a variable (most of the time a global variable) to be exchanged. The function sets this variable to **Value** and returns its prior value.

**\[Expression (Value)]**

The value to be exchanged with the value pointed to by **Target**.

### Description

Sets a variable to the specified value as an atomic operation.

### Return value

Returns the initial value of the **Target** parameter.

### Examples

None

### Remarks

None

### Related

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

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

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

[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_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.
