> For the complete documentation index, see [llms.txt](https://help.trikset.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.trikset.com/en/trik/programming-code/object-threading.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://help.trikset.com/en/trik/programming-code/object-threading.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
