| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
A high-performance C++20 coroutine library designed for batch task processing and high-throughput scenarios.
English | 中文
Performance Data: For detailed performance metrics and benchmarks, see Performance Data Reference
FlowCoro demonstrates good performance compared to Go and Rust in key areas:
Best suited for: Coroutine-based scheduling, batch processing, concurrent task management
git clone https://github.com/caixuf/flowcoro.git
cd flowcoro
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)Note: PGO optimization is automatically enabled when profile data is available in pgo_profiles/ directory.
#include <flowcoro.hpp>
using namespace flowcoro;
// Simple coroutine task
Task<int> compute(int value) {
// Simulate work
co_await sleep_for(std::chrono::milliseconds(10));
co_return value * 2;
}
// Concurrent execution
Task<void> example() {
// Tasks start executing synchronously, then are scheduled when they suspend
auto task1 = compute(10);
auto task2 = compute(20);
auto task3 = compute(30);
// Wait for results
auto result1 = co_await task1;
auto result2 = co_await task2;
auto result3 = co_await task3;
std::cout << "Results: " << result1 << ", " << result2 << ", " << result3 << std::endl;
co_return;
}
// Producer-Consumer with Channel
Task<void> channel_example() {
auto channel = make_channel<int>(10); // Buffer size: 10
// Producer
auto producer = [channel]() -> Task<void> {
for (int i = 0; i < 5; ++i) {
co_await channel->send(i);
std::cout << "Produced: " << i << std::endl;
}
channel->close();
};
// Consumer
auto consumer = [channel]() -> Task<void> {
while (true) {
auto value = co_await channel->recv();
if (!value.has_value()) break; // Channel closed
std::cout << "Consumed: " << value.value() << std::endl;
}
};
auto prod_task = producer();
auto cons_task = consumer();
co_await prod_task;
co_await cons_task;
co_return;
}
int main() {
sync_wait(example());
sync_wait(channel_example());
return 0;
}FlowCoro uses a three-layer scheduling architecture:
Task Creation → Coroutine Manager → Coroutine Pool → Thread Pool
↓ ↓ ↓ ↓
suspend_never Load Balancing Lock-free Queue Execution
Alongside the high-throughput scheduler, FlowCoro ships a single-thread deterministic real-time model (RtExecutor) for latency-critical control loops (robotics / autonomous driving / embedded):
#include <flowcoro/rt_executor.h>
flowcoro::rt::RtExecutor ex{{ .pin_cpu = 2 }};
ex.spawn(periodic_control_task(), "control");
ex.run_blocking(); // periodic ticks until all tasks finish
// or: while (!ex.is_finished()) ex.run();See the complete usage in API Reference §9 and the Autonomous Driving pipeline demo (DDS Pub/Sub + when_any QoS deadline degradation).
Ideal for:
With the Real-Time layer (flowcoro::rt):
Try the Autonomous Driving pipeline demo:
cd build && cmake .. && make ad_pipeline_demo
./examples/autonomous_driving/ad_pipeline_demo 5Enhanced with Channels:
# Run performance tests
./build/benchmarks/professional_flowcoro_benchmark
# Test different scales
./build/examples/hello_world 10000 # 10K tasks
./build/examples/hello_world 100000 # 100K tasksMIT License - see LICENSE file for details.
Contributions are welcome! Please read our contributing guidelines and submit pull requests.
| Back | FazBrowse Home | New Git URL |