# spinlock\_lock\_custom\_wait

### Function

> spinlock\_lock\_custom\_wait

### Syntax

> spinlock\_lock\_custom\_wait( \*Variable, Expression );

### Parameters

**\[\*Variable (Lock)]**

A reference to a variable (most of the time a global variable), used as a [lock](https://en.wikipedia.org/wiki/Spinlock).

**\[Expression]**

A [MASM-like expression](https://docs.hyperdbg.org/commands/scripting-language/assumptions-and-evaluations) to evaluate which is the maximum waiting check for the spinlock to re-check the lock.

{% hint style="info" %}
By default in [spinlock\_lock](https://docs.hyperdbg.org/commands/scripting-language/functions/spinlocks/spinlock_lock), the maximum waiting check is **`65536`**.
{% endhint %}

### Description

Locks the spinlock referred to by lock and also uses the maximum waiting check to re-check the lock. The lock can be unlocked by [spinlock\_unlock](https://docs.hyperdbg.org/commands/scripting-language/functions/spinlocks/spinlock_unlock).

### Return value

None

### Examples

First of all, you should define a global variable and assign zero to it (unlocked state).

`? .my_lock = 0;`

Then, you can use it like this:

`spinlock_lock_custom_wait(&.my_lock, 500);`

The above example locks the spinlock of a global variable (lock) which is called `.my_lock`. It uses **500** as the maximum waiting check. Note that you should use the unary operator `&` to pass a reference of the global variable to this function.

### Remarks

If your lock needs to be checked more frequently, you should specify a lower value as the second argument. However, it's not a power-efficient approach, but it gives you a more real-time spinlock. If you give a number higher than 65536, it takes longer to re-check the lock by the processor.

It's actually the number of times which the **PAUSE** instruction is executed.

### Related

[spinlock\_lock](https://docs.hyperdbg.org/commands/scripting-language/functions/spinlocks/spinlock_lock)

[spinlock\_unlock](https://docs.hyperdbg.org/commands/scripting-language/functions/spinlocks/spinlock_unlock)


---

# 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/spinlocks/spinlock_lock_custom_wait.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.
