Skip to content

Add parallel_for to ThreadPool and ParallelFor convenience function#62

Draft
Copilot wants to merge 7 commits intomainfrom
copilot/replace-taskflow-with-async-system
Draft

Add parallel_for to ThreadPool and ParallelFor convenience function#62
Copilot wants to merge 7 commits intomainfrom
copilot/replace-taskflow-with-async-system

Conversation

Copy link

Copilot AI commented Feb 15, 2026

Adds a parallel_for interface to the custom async task system, enabling index-based parallel iteration distributed across the thread pool.

Changes

  • ThreadPool::parallel_for(begin, end, func) — splits [begin, end) into min(count, numWorkers) balanced chunks, submits each via async(), blocks until complete. Falls back to serial for 0 workers or single element.
  • ParallelFor(begin, end, func) — free function forwarding to the global TaskExecutor singleton's pool.
  • ThreadPool::NumWorkers() — exposes worker thread count.
  • Tests — basic, empty/reversed ranges, single element, large range (10k), convenience function.

Usage

// Direct pool usage
sky::ThreadPool pool(4);
pool.parallel_for(0, N, [&data](int i) {
    data[i] = compute(i);
});

// Via global executor
sky::ParallelFor(0, N, [&data](int i) {
    data[i] = compute(i);
});

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 4 commits February 15, 2026 12:00
Implement ThreadPool and AsyncTaskHandle to replace tf::Executor and
tf::AsyncTask. Update all files that used taskflow types:
- core/async/Task.h, Task.cpp
- core/async/NamedThread.h, NamedThread.cpp
- framework/asset/Asset.h, AssetExecutor.h, AssetExecutor.cpp
- framework/asset/AssetManager.cpp
- render/rdg/RenderGraphContext.h
- render/shader/ShaderFileSystem.h, ShaderFileSystem.cpp
Remove taskflow from CMake dependencies.

Co-authored-by: bluesky013 <35895395+bluesky013@users.noreply.github.com>
Move taskCount.fetch_add() before the lock scope and notify_one() in all
async submission methods to prevent wait_for_all() from returning
prematurely when a task is visible to workers but not yet counted.

Co-authored-by: bluesky013 <35895395+bluesky013@users.noreply.github.com>
Co-authored-by: bluesky013 <35895395+bluesky013@users.noreply.github.com>
Co-authored-by: bluesky013 <35895395+bluesky013@users.noreply.github.com>
Copilot AI changed the title [WIP] Replace existing taskflow with async task management system Replace taskflow with custom ThreadPool-based async task system Feb 15, 2026
Copilot AI requested a review from bluesky013 February 15, 2026 12:06
Copilot AI and others added 2 commits February 16, 2026 01:33
…function

Add ThreadPool::parallel_for(begin, end, func) that distributes
index-based work [begin, end) across worker threads in balanced chunks
and blocks until all iterations complete.

Add ParallelFor(begin, end, func) free function that uses the global
TaskExecutor singleton.

Add ThreadPool::NumWorkers() accessor.

Add tests for basic usage, empty ranges, single element, large range,
and the ParallelFor convenience function.

Co-authored-by: bluesky013 <35895395+bluesky013@users.noreply.github.com>
Co-authored-by: bluesky013 <35895395+bluesky013@users.noreply.github.com>
Copilot AI changed the title Replace taskflow with custom ThreadPool-based async task system Add parallel_for to ThreadPool and ParallelFor convenience function Feb 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants