# Object «Threading»

{% hint style="info" %}
This article is automatically translated from Russian by Google Translator.
{% endhint %}

Provides management of parallel threads.

| Method                                                                         | Description                                                   |
| ------------------------------------------------------------------------------ | ------------------------------------------------------------- |
| [joinThread](/en/trik/programming-code/object-threading.md#jointhread)         | Waiting for the specified flow to complete.                   |
| [killThread](/en/trik/programming-code/object-threading.md#killthread)         | Finishes the execution of the specified flow.                 |
| [receiveMessage](/en/trik/programming-code/object-threading.md#receivemessage) | Queries the received message.                                 |
| [sendMessage](/en/trik/programming-code/object-threading.md#sendmessage)       | Sends a message to the specified stream.                      |
| [startThread](/en/trik/programming-code/object-threading.md#startthread)       | Runs the function passed as a parameter in a separate thread. |

## joinThread

Waiting for the specified flow to complete.

#### Syntax

{% tabs %}
{% tab title="JavaScript" %}

```javascript
Threading.joinThread("threadId");
```

{% endtab %}
{% endtabs %}

As a parameter, it is necessary to specify thread id.

## killThread

Finishes the execution of the specified flow.

#### Syntax

{% tabs %}
{% tab title="JavaScript" %}

```javascript
Threading.killThread("threadId");
```

{% endtab %}
{% endtabs %}

The thread id must be specified as a parameter.

## receiveMessage

Queries the received message.

#### Syntax

{% tabs %}
{% tab title="JavaScript" %}

```javascript
Threading.receiveMessage(wait);
```

{% endtab %}
{% endtabs %}

If `wait` is `true`, it waits until a message arrives.

## sendMessage

Sends a message to the specified stream.

#### Syntax

{% tabs %}
{% tab title="JavaScript" %}

```javascript
Threading.sendMessage("threadId", "message");
```

{% endtab %}
{% endtabs %}

As parameters, it is necessary to specify thread id and message.

## startThread

Runs the function passed as a parameter in a separate thread.

{% hint style="warning" %}
**Warning!** This creates a new copy for all global variables. So if the value of a variable change in one thread, it stays the same in another thread.
{% endhint %}

#### Syntax

{% tabs %}
{% tab title="JavaScript" %}

```javascript
Threading.startThread("newThreadId", "functionName");
```

{% endtab %}
{% endtabs %}

As parameters, it is necessary to specify thread id and function.


---

# 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://help.trikset.com/en/trik/programming-code/object-threading.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.
