Skip to content

About

A simple, lightweight multi-task system (coroutines)

Topics

Resources

Stars

93 stars

Watchers

5 watching

Forks

Repository files navigation

HevTaskSystem

status

HevTaskSystem is a simple, lightweight multi-task system (coroutines) that runs on top of native threads.

Each thread that initializes the task system owns an independent scheduler with an I/O reactor and timer. Any number of tasks can be attached to it, and they run cooperatively: when a task yields, sleeps, or waits for I/O, the scheduler picks the highest-priority runnable task and switches context to it. Tasks within one task system share the memory space, file descriptors, and other resources of the enclosing native thread, while each task keeps its private task structure (#HevTask) and a stack allocated on the heap.

Within a task, you can allocate memory from the heap, read and write data, and perform I/O operations in a synchronous style - blocking the current task only, never the underlying thread or the other tasks.

Features

  • Simple/lightweight task.
  • I/O operations wrapper.
  • Inter-task synchronous. (Mutex/Condition)
  • Inter-task communications. (Channel)
  • Slice-based memory allocator.
  • Call on new stack.
  • Stack memory management. (Release unused stack pages)
  • Multi-thread support.
  • Multi-platform support. (Linux/BSD/macOS/Windows)

How to Build

Unix

git clone https://gitlab.com/hev/hev-task-system
cd hev-task-system
make

# Build shared library
make shared

# Link with librt (only for glibc versions before 2.17)
make LDFLAGS=-lrt

# Disable stack overflow detection
make ENABLE_STACK_OVERFLOW_DETECTION=0

# Set stack backend to heap (Recommended for 32-bit)
make CONFIG_STACK_BACKEND=STACK_HEAP

# Disable sliced memory allocator
make ENABLE_MEMALLOC_SLICE=0

# Disable I/O splice by splice syscall (for old Linux kernel)
make ENABLE_IO_SPLICE_SYSCALL=0

# Set scheduler I/O poll interval in nanoseconds (default: 50000, 0 polls on every schedule pass)
make CONFIG_SCHED_IO_POLL_INTERVAL=0

# Demos
make apps

# Tests
make tests

# Benchmarks
make benches

Android

mkdir hev-task-system
cd hev-task-system
git clone https://gitlab.com/hev/hev-task-system jni
ndk-build

iOS and MacOS

git clone https://gitlab.com/hev/hev-task-system
cd hev-task-system
# will generate HevTaskSystem.xcframework
./build-apple.sh

Windows (MSYS2)

export MSYS=winsymlinks:native
git clone https://gitlab.com/hev/hev-task-system
cd hev-task-system
make

Demos

  1. simple
  2. channel
  3. timeout
  4. wakeup
  5. echo-server
  6. call
  7. gtk
  8. curl

Contributors

License

MIT

About

A simple, lightweight multi-task system (coroutines)

Topics

Resources

Stars

93 stars

Watchers

5 watching

Forks

Releases

Packages

Used by

Contributors

Languages