# Lock: concept and application in variables

The Lock concept refers to a synchronization mechanism designed to prevent the simultaneous alteration of a variable's value during concurrent executions.&#x20;

In **Skyone Studio**, this functionality is essential to ensure data integrity, ensuring that write access to a specific variable occurs in an orderly fashion, regardless of how many flow instances are being processed simultaneously.

<figure><img src="/files/o7mPnnXGLSigXnNNxDW1" alt=""><figcaption><p>The option to enable the use of locks appears when creating or editing a variable.</p></figcaption></figure>

### How it works in practice

In practice, the Lock acts as a sequential access control. When activated, the system follows a suspension logic to avoid conflicts:

* **Write Lock:** If an execution is changing the variable's value, any other execution attempting to read or overwrite that same variable will be temporarily suspended.
* **Execution Queue:** The suspended instance waits until the first execution completes its operation.
* **Context Consistency:** Only after the first execution is released can the next one access and modify the value, ensuring it works with the already updated data.

### Why use this feature?

The main purpose of the Lock is to prevent data loss. In high-demand flows, without this control, an execution could overwrite a variable's value before the previous update was finalized, leading to incorrect calculations and process inconsistencies.

#### Comparative Example: The Impact of Lock

Imagine a variable called `v_counter` starts with the value 10. Two flow instances attempt to add +1 at the same time.

**Scenario A: Without using Lock (risk of inconsistency)**

In this scenario, the executions do not "see" each other, resulting in an error in the final calculation.

| **Step** | **Execution A (Instance 1)** | **Execution A (Instance 2)** | **Variable Value**                                               |
| -------- | ---------------------------- | ---------------------------- | ---------------------------------------------------------------- |
| 1        | Reads value: 10              | Reads value: 10              | 10                                                               |
| 2        | Calculates: $$10+1=11$$      | Calculates: $$10+1=11$$      | 10                                                               |
| 3        | Writes value: 11             | (Waiting for CPU)            | 11                                                               |
| 4        | (Finished)                   | Writes value: 11             | 11 (<mark style="background-color:$danger;">Should be 12</mark>) |

**Scenario B: With Lock active (integrity guarantee)**

With the feature enabled, the system organizes access and the final result is accurate.

| **Step** | **Execution A (Instance 1)** | **Execution A (Instance 2)**               | **Variable Value**                                                         |
| -------- | ---------------------------- | ------------------------------------------ | -------------------------------------------------------------------------- |
| 1        | Locks and reads: 10          | Tries to read and is Suspended             | 10                                                                         |
| 2        | Adds $$10+1=11$$             | Waiting                                    | 10                                                                         |
| 3        | Writes 11 and releases Lock  | Waiting                                    | 11                                                                         |
| 4        | (Finished)                   | <p>Resumes, reads new value: 11</p><p></p> | 11                                                                         |
| 5        |                              | Adds $$11+1=12$$ and writes                | <p>12 (<mark style="background-color:$success;">Success</mark>)</p><p></p> |

Read also: [Variables](/english/skyone-studio/integrations/flows/flow-management/flow-canva-configuring-and-editing-the-flow/flow-settings.md#variables).


---

# 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.skyone.cloud/english/skyone-studio/how-to/lock-concept-and-application-in-variables.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.
