[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6KRCB3HXXR4F8ECETPPXB11":3,"skill-same:01M6KRCB3HXXR4F8ECETPPXB11":65},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":31,"linkOnly":32,"markdownContent":33,"markdownBody":34,"frontMatter":35,"refName":36,"commitSha":37,"skillDirectory":38,"forksCount":39,"repositoryHtmlUrl":40,"repositoryHomepageUrl":6,"ownerHtmlUrl":41,"ownerBlogUrl":42,"ownerDescription":43,"updatedAt":44,"install":45,"resources":58},"01M6KRCB3HXXR4F8ECETPPXB11","multithreading",null,"Use when running work off the main thread — WorkerThreadPool, Thread\u002FMutex\u002FSemaphore, call_deferred, thread-safe scene access, and threaded resource loading","jame581\u002FGodotPrompter","jame581","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F21112138?v=4","01M6KR3KEQ9Z30WVJRR2E2ZVXE","Jan Mesarč","01M6KR3KJVRMPDSMASQPBCBVK3",964,"MIT","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fmultithreading\u002FSKILL.md",[],[5,19,20,21,22,23,24,25,26,27,28,29,30],"safe","semaphore","mutex","access","work","use","main","call","loading","thread","when","running","2026-11-10 10:12:30",false,"---\nname: multithreading\ndescription: Use when running work off the main thread — WorkerThreadPool, Thread\u002FMutex\u002FSemaphore, call_deferred, thread-safe scene access, and threaded resource loading\n---\n\n# Multithreading\n\nRun expensive work off the main thread without corrupting the scene tree. Prefer `WorkerThreadPool` for short parallel jobs; reach for `Thread`\u002F`Mutex`\u002F`Semaphore` only when you need a long-lived worker.\n\n> **Related skills:** **godot-optimization** for profiling before threading, **assets-pipeline** for asset import, **csharp-godot** for C# specifics, **gdscript-advanced** for async\u002Fawait pitfalls.\n\n---\n\n## 1. Threading model & safety rules\n\nThe main thread owns the scene tree — **interacting with the active scene tree is not thread-safe.** Observe these doc-sourced rules:\n\n- **Servers** (RenderingServer, PhysicsServer) are thread-safe **only after enabling it in Project Settings** (`Rendering > Driver > Threads > Thread Model = Separate` — `Multi-Threaded` on 4.3, and experimental; `Physics > {2D,3D} > Run on Separate Thread`). Servers handle thousands of thread-driven instances well.\n- **NavigationServer2D\u002F3D are thread-safe and thread-friendly** (true parallel queries); tune `Navigation > Pathfinding > Max Threads` (4.4+).\n- **AStar2D\u002F3D\u002FGrid2D are NOT thread-safe** — one dedicated thread per object only; sharing one object across threads corrupts data.\n- **GDScript `Array`\u002F`Dictionary`:** reading\u002Fwriting existing elements across threads is OK; **resizing (add\u002Fremove) needs a `Mutex`.**\n- **No GPU work off the main thread** (texture creation, image read\u002Fmodify) — causes RenderingServer sync stalls.\n- **Build scene chunks off-tree** in a thread, then add them on the main thread via `add_child.call_deferred()` — only with a single loader thread (multiple threads risk tweaking the same cached resource → crashes).\n\n> **Golden rule:** Mutate the scene tree only on the main thread. From a worker, hand results back with `call_deferred` \u002F `set_deferred`.\n\n---\n\n## 2. WorkerThreadPool (preferred)\n\n`WorkerThreadPool` is a global singleton with threads allocated at startup. A regular task (`add_task`) runs on one worker; a **group task** (`add_group_task`) is distributed across workers, calling the `Callable` repeatedly for each element index — great for iterating many elements. **Every task must be waited on** (`wait_for_task_completion` \u002F `wait_for_group_task_completion`) or its allocated resources leak. Distributing cheap work can hurt performance — only use it for genuinely expensive work.\n\n### GDScript\n\n```gdscript\nvar enemies = [] # Filled with enemies elsewhere.\n\nfunc process_enemy_ai(enemy_index):\n    var processed_enemy = enemies[enemy_index]\n    # Expensive per-enemy logic...\n\nfunc _process(delta):\n    var task_id = WorkerThreadPool.add_group_task(process_enemy_ai, enemies.size())\n    # ... other main-thread work ...\n    WorkerThreadPool.wait_for_group_task_completion(task_id)\n    # Safe to read results now.\n```\n\n### C# Equivalent\n\n```csharp\nprivate List\u003CNode> _enemies = new(); \u002F\u002F Filled with enemies elsewhere.\n\nprivate void ProcessEnemyAI(int enemyIndex)\n{\n    Node processedEnemy = _enemies[enemyIndex];\n    \u002F\u002F Expensive per-enemy logic...\n}\n\npublic override void _Process(double delta)\n{\n    long taskId = WorkerThreadPool.AddGroupTask(Callable.From\u003Cint>(ProcessEnemyAI), _enemies.Count);\n    \u002F\u002F ... other main-thread work ...\n    WorkerThreadPool.WaitForGroupTaskCompletion(taskId);\n    \u002F\u002F Safe to read results now.\n}\n```\n\nThis relies on the element count staying constant during the multithreaded part.\n\n---\n\n## 3. Thread \u002F Mutex \u002F Semaphore\n\nReal signatures: `Thread.start(callable: Callable, priority := PRIORITY_NORMAL)`, `wait_to_finish()` (blocks; join before free), `is_alive()`. `Mutex` is reentrant (`lock`\u002F`unlock`\u002F`try_lock`). `Semaphore` exposes `wait()` \u002F `post()` (`post(count := 1)` from 4.4).\n\n### GDScript\n\nThe canonical semaphore producer\u002Fconsumer + clean-shutdown idiom:\n\n```gdscript\nvar counter := 0\nvar mutex: Mutex\nvar semaphore: Semaphore\nvar thread: Thread\nvar exit_thread := false\n\nfunc _ready():\n    mutex = Mutex.new()\n    semaphore = Semaphore.new()\n    thread = Thread.new()\n    thread.start(_thread_function)\n\nfunc _thread_function():\n    while true:\n        semaphore.wait() # Block until there is work.\n\n        mutex.lock()\n        var should_exit = exit_thread\n        mutex.unlock()\n        if should_exit:\n            break\n\n        mutex.lock()\n        counter += 1\n        mutex.unlock()\n\nfunc increment_counter():\n    semaphore.post() # Wake the worker.\n\nfunc _exit_tree():\n    mutex.lock()\n    exit_thread = true\n    mutex.unlock()\n    semaphore.post()        # Unblock so it can see exit_thread.\n    thread.wait_to_finish() # Join.\n```\n\n### C# Equivalent\n\n`Godot.Mutex`\u002F`Godot.Semaphore` also exist, but `System.Threading` is idiomatic in C#:\n\n```csharp\nusing Godot;\nusing System.Threading;\n\npublic partial class Worker : Node\n{\n    private int _counter;\n    private readonly object _lock = new();\n    private readonly SemaphoreSlim _semaphore = new(0);\n    private Thread _thread;\n    private volatile bool _exitThread;\n\n    public override void _Ready()\n    {\n        _thread = new Thread(ThreadFunction) { IsBackground = true };\n        _thread.Start();\n    }\n\n    private void ThreadFunction()\n    {\n        while (true)\n        {\n            _semaphore.Wait();           \u002F\u002F Block until there is work.\n            if (_exitThread) break;\n            lock (_lock) { _counter++; }\n        }\n    }\n\n    public void IncrementCounter() => _semaphore.Release(); \u002F\u002F Wake the worker.\n\n    public override void _ExitTree()\n    {\n        _exitThread = true;\n        _semaphore.Release();            \u002F\u002F Unblock so it can see _exitThread.\n        _thread.Join();                  \u002F\u002F Join.\n    }\n}\n```\n\nThread creation is slow (especially on Windows) — pre-create before heavy work, not just-in-time. Over-locking mutexes is also costly.\n\n---\n\n## 4. Handing results back: call_deferred \u002F set_deferred\n\n### GDScript\n\n```gdscript\n# Unsafe from a worker thread:\nworld.add_child(enemy)\n# Safe:\nworld.add_child.call_deferred(enemy)\n```\n\n### C# Equivalent\n\n```csharp\n\u002F\u002F Unsafe from a worker thread:\nworld.AddChild(enemy);\n\u002F\u002F Safe — use the MethodName StringName constant, NOT \"AddChild\":\nworld.CallDeferred(Node.MethodName.AddChild, enemy);\n```\n\nIn C#, `CallDeferred(\"AddChild\")` fails — the deferred\u002F`Call`\u002F`Connect` APIs use Godot's snake_case names. Prefer the `Node.MethodName.*` constants (avoids the pitfall and an allocation).\n\n---\n\n## 5. Threaded resource loading\n\n`ResourceLoader.load_threaded_request(path)` starts the load. Poll `load_threaded_get_status(path, progress)` each frame (`progress[0]` is the 0–1 ratio); on `THREAD_LOAD_LOADED` call `load_threaded_get(path)`. **`load_threaded_get` blocks like `load()` if the load is not finished** — always poll first. Statuses: `THREAD_LOAD_INVALID_RESOURCE` \u002F `THREAD_LOAD_IN_PROGRESS` \u002F `THREAD_LOAD_FAILED` \u002F `THREAD_LOAD_LOADED`.\n\n### GDScript\n\n```gdscript\nconst SCENE_PATH := \"res:\u002F\u002Fenemy.tscn\"\nvar _progress: Array = []\n\nfunc _ready():\n    ResourceLoader.load_threaded_request(SCENE_PATH)\n\nfunc _process(_delta):\n    var status := ResourceLoader.load_threaded_get_status(SCENE_PATH, _progress)\n    match status:\n        ResourceLoader.THREAD_LOAD_IN_PROGRESS:\n            $ProgressBar.value = _progress[0] * 100.0\n        ResourceLoader.THREAD_LOAD_LOADED:\n            var scene: PackedScene = ResourceLoader.load_threaded_get(SCENE_PATH)\n            add_child(scene.instantiate())\n            set_process(false)\n        ResourceLoader.THREAD_LOAD_FAILED, ResourceLoader.THREAD_LOAD_INVALID_RESOURCE:\n            push_error(\"Threaded load failed: %s\" % SCENE_PATH)\n            set_process(false)\n```\n\n### C# Equivalent\n\n```csharp\nprivate const string ScenePath = \"res:\u002F\u002Fenemy.tscn\";\nprivate readonly Godot.Collections.Array _progress = new();\n\npublic override void _Ready() => ResourceLoader.LoadThreadedRequest(ScenePath);\n\npublic override void _Process(double delta)\n{\n    var status = ResourceLoader.LoadThreadedGetStatus(ScenePath, _progress);\n    switch (status)\n    {\n        case ResourceLoader.ThreadLoadStatus.InProgress:\n            GetNode\u003CProgressBar>(\"ProgressBar\").Value = (double)_progress[0] * 100.0;\n            break;\n        case ResourceLoader.ThreadLoadStatus.Loaded:\n            var scene = (PackedScene)ResourceLoader.LoadThreadedGet(ScenePath);\n            AddChild(scene.Instantiate());\n            SetProcess(false);\n            break;\n        case ResourceLoader.ThreadLoadStatus.Failed:\n        case ResourceLoader.ThreadLoadStatus.InvalidResource:\n            GD.PushError($\"Threaded load failed: {ScenePath}\");\n            SetProcess(false);\n            break;\n    }\n}\n```\n\n> **Godot 4.7+:** 4.7 shipped several threaded-load correctness fixes — `load_threaded_get()` deadlocks ([GH-119757](https:\u002F\u002Fgithub.com\u002Fgodotengine\u002Fgodot\u002Fpull\u002F119757), [GH-120077](https:\u002F\u002Fgithub.com\u002Fgodotengine\u002Fgodot\u002Fpull\u002F120077)), a race in `load_threaded_request()` ([GH-118824](https:\u002F\u002Fgithub.com\u002Fgodotengine\u002Fgodot\u002Fpull\u002F118824)), and resources returned by `load_threaded_get()` never being unloaded ([GH-119394](https:\u002F\u002Fgithub.com\u002Fgodotengine\u002Fgodot\u002Fpull\u002F119394)). No API change; if you carry workarounds for rare threaded-load hangs or leaks from earlier versions, re-test on 4.7 before keeping them. The poll-before-get rule above still applies.\n\n---\n\n## 6. C# concurrency: Tasks vs Godot threads\n\nIn C#, prefer `System.Threading.Tasks.Task.Run` \u002F `async`-`await` for fire-and-forget CPU work; **never touch Godot objects or `await ToSignal(...)` from a background thread** — marshal results back with `CallDeferred`. Use `WorkerThreadPool` when you want Godot's pool and engine integration; use `Task` when you want .NET idioms. (GDScript users: use `WorkerThreadPool` or `Thread` from the sections above.)\n\n```csharp\npublic override void _Process(double delta)\n{\n    if (Input.IsActionJustPressed(\"compute\"))\n    {\n        _ = System.Threading.Tasks.Task.Run(() =>\n        {\n            int result = ExpensiveComputation();   \u002F\u002F Pure CPU work, no Godot objects.\n            CallDeferred(MethodName.OnComputed, result); \u002F\u002F Marshal back to main thread.\n        });\n    }\n}\n\nprivate void OnComputed(int result) => GD.Print($\"Done: {result}\");\n```\n\n> **Deeper:** see [Pitfalls & deadlocks](references\u002Fpitfalls.md) for data races, the `ERR_BUSY` nested-wait deadlock, and when threading hurts.\n\n---\n\n## Implementation Checklist\n\n- [ ] Profiled first — confirmed the work is genuinely CPU-expensive (see **godot-optimization**)\n- [ ] Scene-tree mutations happen only on the main thread (`call_deferred` \u002F `set_deferred`)\n- [ ] Every `WorkerThreadPool` task is waited on (`wait_for_*_completion`)\n- [ ] Shared state guarded by a `Mutex` \u002F `lock`; container resizes are locked\n- [ ] Threads joined (`wait_to_finish` \u002F `Join`) before the owning node frees\n- [ ] No GPU calls, no AStar sharing, no same-resource loads across threads\n- [ ] Threaded loads poll status before calling `load_threaded_get`\n","# Multithreading\n\nRun expensive work off the main thread without corrupting the scene tree. Prefer `WorkerThreadPool` for short parallel jobs; reach for `Thread`\u002F`Mutex`\u002F`Semaphore` only when you need a long-lived worker.\n\n> **Related skills:** **godot-optimization** for profiling before threading, **assets-pipeline** for asset import, **csharp-godot** for C# specifics, **gdscript-advanced** for async\u002Fawait pitfalls.\n\n---\n\n## 1. Threading model & safety rules\n\nThe main thread owns the scene tree — **interacting with the active scene tree is not thread-safe.** Observe these doc-sourced rules:\n\n- **Servers** (RenderingServer, PhysicsServer) are thread-safe **only after enabling it in Project Settings** (`Rendering > Driver > Threads > Thread Model = Separate` — `Multi-Threaded` on 4.3, and experimental; `Physics > {2D,3D} > Run on Separate Thread`). Servers handle thousands of thread-driven instances well.\n- **NavigationServer2D\u002F3D are thread-safe and thread-friendly** (true parallel queries); tune `Navigation > Pathfinding > Max Threads` (4.4+).\n- **AStar2D\u002F3D\u002FGrid2D are NOT thread-safe** — one dedicated thread per object only; sharing one object across threads corrupts data.\n- **GDScript `Array`\u002F`Dictionary`:** reading\u002Fwriting existing elements across threads is OK; **resizing (add\u002Fremove) needs a `Mutex`.**\n- **No GPU work off the main thread** (texture creation, image read\u002Fmodify) — causes RenderingServer sync stalls.\n- **Build scene chunks off-tree** in a thread, then add them on the main thread via `add_child.call_deferred()` — only with a single loader thread (multiple threads risk tweaking the same cached resource → crashes).\n\n> **Golden rule:** Mutate the scene tree only on the main thread. From a worker, hand results back with `call_deferred` \u002F `set_deferred`.\n\n---\n\n## 2. WorkerThreadPool (preferred)\n\n`WorkerThreadPool` is a global singleton with threads allocated at startup. A regular task (`add_task`) runs on one worker; a **group task** (`add_group_task`) is distributed across workers, calling the `Callable` repeatedly for each element index — great for iterating many elements. **Every task must be waited on** (`wait_for_task_completion` \u002F `wait_for_group_task_completion`) or its allocated resources leak. Distributing cheap work can hurt performance — only use it for genuinely expensive work.\n\n### GDScript\n\n```gdscript\nvar enemies = [] # Filled with enemies elsewhere.\n\nfunc process_enemy_ai(enemy_index):\n    var processed_enemy = enemies[enemy_index]\n    # Expensive per-enemy logic...\n\nfunc _process(delta):\n    var task_id = WorkerThreadPool.add_group_task(process_enemy_ai, enemies.size())\n    # ... other main-thread work ...\n    WorkerThreadPool.wait_for_group_task_completion(task_id)\n    # Safe to read results now.\n```\n\n### C# Equivalent\n\n```csharp\nprivate List\u003CNode> _enemies = new(); \u002F\u002F Filled with enemies elsewhere.\n\nprivate void ProcessEnemyAI(int enemyIndex)\n{\n    Node processedEnemy = _enemies[enemyIndex];\n    \u002F\u002F Expensive per-enemy logic...\n}\n\npublic override void _Process(double delta)\n{\n    long taskId = WorkerThreadPool.AddGroupTask(Callable.From\u003Cint>(ProcessEnemyAI), _enemies.Count);\n    \u002F\u002F ... other main-thread work ...\n    WorkerThreadPool.WaitForGroupTaskCompletion(taskId);\n    \u002F\u002F Safe to read results now.\n}\n```\n\nThis relies on the element count staying constant during the multithreaded part.\n\n---\n\n## 3. Thread \u002F Mutex \u002F Semaphore\n\nReal signatures: `Thread.start(callable: Callable, priority := PRIORITY_NORMAL)`, `wait_to_finish()` (blocks; join before free), `is_alive()`. `Mutex` is reentrant (`lock`\u002F`unlock`\u002F`try_lock`). `Semaphore` exposes `wait()` \u002F `post()` (`post(count := 1)` from 4.4).\n\n### GDScript\n\nThe canonical semaphore producer\u002Fconsumer + clean-shutdown idiom:\n\n```gdscript\nvar counter := 0\nvar mutex: Mutex\nvar semaphore: Semaphore\nvar thread: Thread\nvar exit_thread := false\n\nfunc _ready():\n    mutex = Mutex.new()\n    semaphore = Semaphore.new()\n    thread = Thread.new()\n    thread.start(_thread_function)\n\nfunc _thread_function():\n    while true:\n        semaphore.wait() # Block until there is work.\n\n        mutex.lock()\n        var should_exit = exit_thread\n        mutex.unlock()\n        if should_exit:\n            break\n\n        mutex.lock()\n        counter += 1\n        mutex.unlock()\n\nfunc increment_counter():\n    semaphore.post() # Wake the worker.\n\nfunc _exit_tree():\n    mutex.lock()\n    exit_thread = true\n    mutex.unlock()\n    semaphore.post()        # Unblock so it can see exit_thread.\n    thread.wait_to_finish() # Join.\n```\n\n### C# Equivalent\n\n`Godot.Mutex`\u002F`Godot.Semaphore` also exist, but `System.Threading` is idiomatic in C#:\n\n```csharp\nusing Godot;\nusing System.Threading;\n\npublic partial class Worker : Node\n{\n    private int _counter;\n    private readonly object _lock = new();\n    private readonly SemaphoreSlim _semaphore = new(0);\n    private Thread _thread;\n    private volatile bool _exitThread;\n\n    public override void _Ready()\n    {\n        _thread = new Thread(ThreadFunction) { IsBackground = true };\n        _thread.Start();\n    }\n\n    private void ThreadFunction()\n    {\n        while (true)\n        {\n            _semaphore.Wait();           \u002F\u002F Block until there is work.\n            if (_exitThread) break;\n            lock (_lock) { _counter++; }\n        }\n    }\n\n    public void IncrementCounter() => _semaphore.Release(); \u002F\u002F Wake the worker.\n\n    public override void _ExitTree()\n    {\n        _exitThread = true;\n        _semaphore.Release();            \u002F\u002F Unblock so it can see _exitThread.\n        _thread.Join();                  \u002F\u002F Join.\n    }\n}\n```\n\nThread creation is slow (especially on Windows) — pre-create before heavy work, not just-in-time. Over-locking mutexes is also costly.\n\n---\n\n## 4. Handing results back: call_deferred \u002F set_deferred\n\n### GDScript\n\n```gdscript\n# Unsafe from a worker thread:\nworld.add_child(enemy)\n# Safe:\nworld.add_child.call_deferred(enemy)\n```\n\n### C# Equivalent\n\n```csharp\n\u002F\u002F Unsafe from a worker thread:\nworld.AddChild(enemy);\n\u002F\u002F Safe — use the MethodName StringName constant, NOT \"AddChild\":\nworld.CallDeferred(Node.MethodName.AddChild, enemy);\n```\n\nIn C#, `CallDeferred(\"AddChild\")` fails — the deferred\u002F`Call`\u002F`Connect` APIs use Godot's snake_case names. Prefer the `Node.MethodName.*` constants (avoids the pitfall and an allocation).\n\n---\n\n## 5. Threaded resource loading\n\n`ResourceLoader.load_threaded_request(path)` starts the load. Poll `load_threaded_get_status(path, progress)` each frame (`progress[0]` is the 0–1 ratio); on `THREAD_LOAD_LOADED` call `load_threaded_get(path)`. **`load_threaded_get` blocks like `load()` if the load is not finished** — always poll first. Statuses: `THREAD_LOAD_INVALID_RESOURCE` \u002F `THREAD_LOAD_IN_PROGRESS` \u002F `THREAD_LOAD_FAILED` \u002F `THREAD_LOAD_LOADED`.\n\n### GDScript\n\n```gdscript\nconst SCENE_PATH := \"res:\u002F\u002Fenemy.tscn\"\nvar _progress: Array = []\n\nfunc _ready():\n    ResourceLoader.load_threaded_request(SCENE_PATH)\n\nfunc _process(_delta):\n    var status := ResourceLoader.load_threaded_get_status(SCENE_PATH, _progress)\n    match status:\n        ResourceLoader.THREAD_LOAD_IN_PROGRESS:\n            $ProgressBar.value = _progress[0] * 100.0\n        ResourceLoader.THREAD_LOAD_LOADED:\n            var scene: PackedScene = ResourceLoader.load_threaded_get(SCENE_PATH)\n            add_child(scene.instantiate())\n            set_process(false)\n        ResourceLoader.THREAD_LOAD_FAILED, ResourceLoader.THREAD_LOAD_INVALID_RESOURCE:\n            push_error(\"Threaded load failed: %s\" % SCENE_PATH)\n            set_process(false)\n```\n\n### C# Equivalent\n\n```csharp\nprivate const string ScenePath = \"res:\u002F\u002Fenemy.tscn\";\nprivate readonly Godot.Collections.Array _progress = new();\n\npublic override void _Ready() => ResourceLoader.LoadThreadedRequest(ScenePath);\n\npublic override void _Process(double delta)\n{\n    var status = ResourceLoader.LoadThreadedGetStatus(ScenePath, _progress);\n    switch (status)\n    {\n        case ResourceLoader.ThreadLoadStatus.InProgress:\n            GetNode\u003CProgressBar>(\"ProgressBar\").Value = (double)_progress[0] * 100.0;\n            break;\n        case ResourceLoader.ThreadLoadStatus.Loaded:\n            var scene = (PackedScene)ResourceLoader.LoadThreadedGet(ScenePath);\n            AddChild(scene.Instantiate());\n            SetProcess(false);\n            break;\n        case ResourceLoader.ThreadLoadStatus.Failed:\n        case ResourceLoader.ThreadLoadStatus.InvalidResource:\n            GD.PushError($\"Threaded load failed: {ScenePath}\");\n            SetProcess(false);\n            break;\n    }\n}\n```\n\n> **Godot 4.7+:** 4.7 shipped several threaded-load correctness fixes — `load_threaded_get()` deadlocks ([GH-119757](https:\u002F\u002Fgithub.com\u002Fgodotengine\u002Fgodot\u002Fpull\u002F119757), [GH-120077](https:\u002F\u002Fgithub.com\u002Fgodotengine\u002Fgodot\u002Fpull\u002F120077)), a race in `load_threaded_request()` ([GH-118824](https:\u002F\u002Fgithub.com\u002Fgodotengine\u002Fgodot\u002Fpull\u002F118824)), and resources returned by `load_threaded_get()` never being unloaded ([GH-119394](https:\u002F\u002Fgithub.com\u002Fgodotengine\u002Fgodot\u002Fpull\u002F119394)). No API change; if you carry workarounds for rare threaded-load hangs or leaks from earlier versions, re-test on 4.7 before keeping them. The poll-before-get rule above still applies.\n\n---\n\n## 6. C# concurrency: Tasks vs Godot threads\n\nIn C#, prefer `System.Threading.Tasks.Task.Run` \u002F `async`-`await` for fire-and-forget CPU work; **never touch Godot objects or `await ToSignal(...)` from a background thread** — marshal results back with `CallDeferred`. Use `WorkerThreadPool` when you want Godot's pool and engine integration; use `Task` when you want .NET idioms. (GDScript users: use `WorkerThreadPool` or `Thread` from the sections above.)\n\n```csharp\npublic override void _Process(double delta)\n{\n    if (Input.IsActionJustPressed(\"compute\"))\n    {\n        _ = System.Threading.Tasks.Task.Run(() =>\n        {\n            int result = ExpensiveComputation();   \u002F\u002F Pure CPU work, no Godot objects.\n            CallDeferred(MethodName.OnComputed, result); \u002F\u002F Marshal back to main thread.\n        });\n    }\n}\n\nprivate void OnComputed(int result) => GD.Print($\"Done: {result}\");\n```\n\n> **Deeper:** see [Pitfalls & deadlocks](references\u002Fpitfalls.md) for data races, the `ERR_BUSY` nested-wait deadlock, and when threading hurts.\n\n---\n\n## Implementation Checklist\n\n- [ ] Profiled first — confirmed the work is genuinely CPU-expensive (see **godot-optimization**)\n- [ ] Scene-tree mutations happen only on the main thread (`call_deferred` \u002F `set_deferred`)\n- [ ] Every `WorkerThreadPool` task is waited on (`wait_for_*_completion`)\n- [ ] Shared state guarded by a `Mutex` \u002F `lock`; container resizes are locked\n- [ ] Threads joined (`wait_to_finish` \u002F `Join`) before the owning node frees\n- [ ] No GPU calls, no AStar sharing, no same-resource loads across threads\n- [ ] Threaded loads poll status before calling `load_threaded_get`\n",{"name":5,"description":7},"master","d7b26cdb5fae14d4ef7b713c5bf259395e75c3c6","skills\u002Fmultithreading",63,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter","https:\u002F\u002Fgithub.com\u002Fjame581","https:\u002F\u002Fjanmesarc.online\u002F","Software engineer. My biggest passion is game development.","2026-11-14 20:45:49",{"source":8,"skillName":5,"commands":46,"prompt":56,"zipAvailable":57},[47,50,53],{"tool":48,"command":49},"npx","npx skills add jame581\u002FGodotPrompter --skill multithreading",{"tool":51,"command":52},"bunx","bunx skills add jame581\u002FGodotPrompter --skill multithreading",{"tool":54,"command":55},"pnpm","pnpm dlx skills add jame581\u002FGodotPrompter --skill multithreading","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fmultithreading\u002FSKILL.md",true,[59],{"path":60,"resourceType":61,"resourceTypeDesc":62,"sizeBytes":63,"sourceHtmlUrl":64},"references\u002Fpitfalls.md","REFERENCE","参考文档",4254,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fmultithreading\u002Freferences\u002Fpitfalls.md",[66,86,107,137,161,179],{"skillNo":67,"name":68,"nameZh":6,"description":69,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":70,"categories":71,"keywords":72,"publishedAt":31},"01M6KRFE5BR2PSD08ZKDAS66R7","xr-development","Use when building VR\u002FAR\u002FXR applications — OpenXR setup, XROrigin3D, hand tracking, controllers, passthrough, and Meta Quest deployment in Godot 4.3+","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fxr-development\u002FSKILL.md",[],[73,74,29,75,76,77,78,79,80,81,82,24,83,84,85],"xr development","development","deployment","godot","vr","setup","tracking","godot 4","ar","hand","Meta","applications","quest",{"skillNo":87,"name":88,"nameZh":6,"description":89,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":90,"categories":91,"keywords":92,"publishedAt":31},"01M6KRF8GZTG1TAS506MFBSGFC","web-services","Use when a Godot game calls a web server — HTTPRequest, downloads, REST\u002FJSON APIs, auth headers, WebSocketPeer clients, TLS, retries, and keeping secrets out of the build. Not for game networking\u002FRPCs (multiplayer-basics) or browser export (web-export)","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fweb-services\u002FSKILL.md",[],[93,94,95,96,97,98,99,100,24,29,76,101,102,103,104,105,106],"web services","web","services","tls","retries","calling","auth","downloads","clients","headers","secrets","json","build","REST",{"skillNo":108,"name":109,"nameZh":6,"description":110,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":111,"categories":112,"keywords":118,"publishedAt":31},"01M6KRF38Q4WSKAYFS56PG87T0","web-export","Use when shipping a Godot game to the browser — Web export preset options, threads vs no-threads and COOP\u002FCOEP headers, hosting on itch.io or your own server, PWA, JavaScriptBridge, user:\u002F\u002F persistence, audio and input limits, and load size","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fweb-export\u002FSKILL.md",[113],{"categoryNo":114,"categoryName":115,"taxonomyType":116,"taxonomyTypeDesc":117},"01JBSEEDCAT000000000000016","图像与多媒体","SCENARIO","使用场景",[94,119,120,121,122,123,124,125,102,126,127,29,128,129,130,131,132,133,24,134,135,136],"export","web export","threads","limits","shipping","size","options","hosting","input","Coop","preset","browser","game","io","load","pwa","Audio","server",{"skillNo":138,"name":139,"nameZh":6,"description":140,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":141,"categories":142,"keywords":151,"publishedAt":31},"01M6KREYFETEBH62ZTN6EZH2X3","using-godot-prompter","Bootstrap skill — establishes how to find and use GodotPrompter skills, with platform-specific tool mapping","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fusing-godot-prompter\u002FSKILL.md",[143,146],{"categoryNo":144,"categoryName":145,"taxonomyType":116,"taxonomyTypeDesc":117},"01JBSEEDCAT000000000000023","Skill与智能体开发",{"categoryNo":147,"categoryName":148,"taxonomyType":149,"taxonomyTypeDesc":150},"01JBSEEDCAT000000000000032","设计师","PROFESSION","适用职业",[76,152,153,154,155,24,156,157,158,159,160],"using godot prompter","find","with","bootstrap","tool","platform","mapping","how","how to",{"skillNo":162,"name":163,"nameZh":6,"description":164,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":165,"categories":166,"keywords":167,"publishedAt":31},"01M6KRER5G7EQWKGAFN8QJKQ69","tween-animation","Use when implementing tweens — property animation, method tweening, chaining, parallel sequences, easing, and common UI\u002Fgameplay motion recipes","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Ftween-animation\u002FSKILL.md",[],[168,169,24,170,171,172,173,174,175,176,177,29,178],"tween animation","Animation","motion","parallel","gameplay","chaining","ui","recipes","common","implementing","sequences",{"skillNo":180,"name":181,"nameZh":6,"description":182,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":183,"categories":184,"keywords":185,"publishedAt":31},"01M6KREKGCQMVDV8WX7HWX8BZG","state-machine","Use when building a state machine or refactoring logic into one — enum, node, and resource-based FSM patterns with trade-offs. Not for adding states to an existing one","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fstate-machine\u002FSKILL.md",[],[186,187,188,76,29,189,190,191,192,193,154,24,177,194],"state","state machine","machine","patterns","node","fsm","state machines","trade","trade-offs"]