目录

ArkCompiler: Detecting Runtime Issues

Multi Thread Check

In the JavaScript runtime environment, the safety of multi-threading is an important consideration. Since JavaScript is a single-threaded language, any JavaScript object can only be operated on the thread where it is created. Violating this rule can lead to multi-threading safety issues. Here are some detailed explanations on how to determine and handle these issues. Enabling multi-thread check will cause significant performance loss. Enable it as needed.

[h2]Technical Overview

[h2]Common Multithreading Safety Issues

Identifying Multithreading Safety Issues

If you encounter the following fatal error message during runtime, it means a multithreading safety issue has occurred:

Fatal: ecma_vm cannot run in multi-thread! thread:3096 currentThread:3550

The current thread number is 3550, and the JavaScript environment used is created by thread 3096. This indicates that the virtual machine environment (vm/env) is being used across threads, leading to a multithreading safety issue.

If multi-thread check is not enabled, an error may not be reported in runtime even if there is an incorrect multi-thread implementation.

[h2]Constraints

Multi thread check can only be initiated through the command line.

[h2]Enabling Multi Thread Check

You can enable multi thread check in either of the following ways:

[h2]Using Multi Thread Check

  1. Run or debug the app.
  2. When a multithreading safety issue occurs, the crash log message will be displayed. You can click the link provided in the message to navigate to the code that causes the issue.

[h2]ArkCompiler Error Codes

The fatal message "Fatal: ecma_vm cannot run in multi-thread! thread:20296 currentThread:19953" indicates a multithreading safety issue. It means that the current thread (ID: 19953) uses a JavaScript environment created by thread 20296, resulting in cross-thread VM access.