Skip to content
ffredyk edited this page Jul 23, 2026 · 1 revision

sendTo

Category

Scheduler Management / Thread Safety

Arity

Binary<array> sendTo <schedulerId>.

<array> sendTo <number>

Description

Transfers ownership of an array to another scheduler. The array is moved from the current scheduler's ownership to the target scheduler. Returns a new array reference that is valid on the target scheduler.

After transfer, the original array reference is invalidated — accessing it from the original scheduler will throw an ownership error.

How It Works

Marks the array's ownership as transferred to the target scheduler. The array's data is not copied — this is a transfer of ownership, not a copy. The target scheduler can then freely mutate the array. The source scheduler loses access.

Usage

Transfer to another scheduler

_arr = [1, 2, 3, 4, 5];
_arr sendTo 2;                 // array now owned by scheduler 2
// _arr is now INVALID on this scheduler

Work distribution pattern

// Scheduler 1: prepare data
_data = collectGameState();    // builds array
_data sendTo 2;                // transfer to AI scheduler

// Scheduler 2 (via spawnOn): receive and process
// (the transfer must be coordinated via other means — 
//  typically the array reference is passed via spawnOn args)

With spawnOn

_data = [1, 2, 3];
// freeze for safe cross-scheduler sharing:
_frozen = freeze _data;
[freeze _data] spawnOn ["AI", {
    params ["_frozenData"];
    _local = thaw _frozenData;
    _local pushBack 4;         // mutate local copy
}];

Safe transfer check

_targetId = 2;
if (schedulerExists _targetId) then {
    _data sendTo _targetId;
} else {
    systemChat "Target scheduler does not exist";
};

Thread Safety

Thread-safe transfer mechanism. The ownership change is atomic — no other fiber can access the array during the transfer window. After transfer, the source scheduler's reference is invalidated.

See Also

  • freeze — safer cross-scheduler sharing (immutable snapshot)
  • thaw — create mutable copy from frozen
  • scheduler — get value's owner
  • isSchedulerLocal — check ownership
  • spawnOn — spawn on target scheduler

SQ# Wiki

Home

Engine Docs

Migration

Commands

Value Constructors

Arithmetic

Comparison

Logic

Array

String

Math

Random

Type & Introspection

HashMap

Code Execution

Concurrency

Scheduler

Thread Safety

Error

Output

Time

Multiplayer

Compiler

Clone this wiki locally