Zero-task allocation overhead and ultra-low context-switching scheduling for your projects.
Currently Project is written in C and Zig, however it will be transitioned to fully Zig once functionality is implemented for better performance.
CompOS recognizes existing RTOS structures and mimics them at a lower-cost, more performant abstraction through utilizing the power of new compiler features that Zig and C++ offer. (Benchmarks are not done yet but it would be 1.5x performance while being slightly better memory efficiency). This library can be used with any C ABI-compatible languages.
--
- Require separate stacks for each task, consuming significant memory.
- Use manual creation and management via
xTaskCreate, leading to verbose code. - Depend on synchronization mechanisms like semaphores or notifications, adding complexity.
- Suffer memory overhead due to pre-allocated stacks, regardless of actual usage.
- Introduce context switching latency, which impacts real-time responsiveness.
- State Machines Replace Stacks:
- Zig coroutines store only the minimal state (variables and execution point), eliminating the need for per-task stacks.
- Explicit Control with
await:- Coroutines yield control explicitly at
await, making them cooperative and reducing unnecessary context switches.
- Coroutines yield control explicitly at
- Reduced Memory Usage:
- Tasks no longer require stacks, dramatically decreasing memory consumption.
- Simplified Task Model:
- Fewer APIs and boilerplate code compared to traditional task creation and management.
- Compile-Time Optimization with
comptime:- Know the exact number of coroutines at compile time, enabling aggressive memory and performance optimizations.
- Eliminate Heap Usage:
- With all tasks and resources defined at compile time, the system can operate entirely without a heap.
-
Unit Testing:
- No need for google tests, instead use Zig's built in testing framework.
Just Run:
zig build -Dtest=true test --summary all
Add the following dependency to your build.zig.zon to integrate CompOS into your project:
📄 build.zig.zon:
.dependencies = .{
.CompOS = .{
.url = "https://github.com/OmarSiwy/CompOS/archive/refs/tags/v0.0.6.tar.gz",
.hash = "12206cc38df5a25da72f1214c8e1bc019f3dbd5c0fd358b229de40dcb5f97abc770c",
},
},📄 build.zig:
const ARTOS = b.dependency("CompOS", .{
.Compile_Target = "<MCU_NAME>",
.Optimization = "ReleaseSafe or Debug or ReleaseSmall or ...",
.Library_Type = "Static or Shared",
});
// Your project setup:
const exe = b.addExecutable(.{
.name = "project",
.target = target,
.optimize = optimize,
.root_source_file = .{ .cwd_relative = "src/main.zig" },
.linkerscript = output_path,
});
exe.linkLibrary(ARTOS.artifact("CompOS"));To build and use CompOS with C/C++:
zig build -Doptimize=ReleaseSafe -DCompile_Target=testing -DLibrary_Type=Static
# Use the generated library and source files with your makefile (see examples for details).Run tests with the following command:
zig build -Doptimize=ReleaseSafe -DCompile_Target=testing -DLibrary_Type=Static cdb # Generate Compile Commands file
zig build -Doptimize=ReleaseSafe -DCompile_Target=testing -DLibrary_Type=Static size # Find Library SizeTo build CompOS for your project:
zig build -Doptimize=ReleaseSafe -DCompile_Target=testing -DLibrary_Type=Static cdb # Nested Compile Commands for your project <3