Skip to content

Thread Safety

v2rayroot edited this page Jun 14, 2026 · 1 revision

Thread Safety

Lifecycle

Start, Stop, and GetStatus synchronize global runtime state. Applications should still serialize lifecycle commands to avoid confusing user-visible transitions.

One Runtime

Only one engine is supported per process. Use separate processes for isolation.

Statistics

Realtime speed callers share one baseline. Designate one polling task.

Parsers

Parser calls can update the process-wide XRAY_LOCATION_ASSET environment variable. Serialize calls that use different asset directories.

Latency

TestLatency runs entries concurrently. Limit batch size to control CPU, memory, sockets, and file descriptors.

Unloading

Never unload the shared library while:

  • Xray is running
  • Native calls are active
  • Returned native strings are still owned by the application

Clone this wiki locally