# sendTo ## Category Scheduler Management / Thread Safety ## Arity **Binary** — ` sendTo `. ``` sendTo ``` ## 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 ```sqf _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 ```sqf // 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 ```sqf _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 ```sqf _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](freeze.md) — safer cross-scheduler sharing (immutable snapshot) - [thaw](thaw.md) — create mutable copy from frozen - [scheduler](scheduler.md) — get value's owner - [isSchedulerLocal](isSchedulerLocal.md) — check ownership - [spawnOn](spawnOn.md) — spawn on target scheduler