tunkI is a high-performance, experimental task scheduler that bridges the gap between Go's high-level abstractions and C's raw execution power. It allows you to offload Go functions to a pool of real OS threads (pthreads) managed in C, providing a unique environment for exploring custom scheduling, cross-language parallelism, and low-level runtime mechanics.
While Go's standard goroutine model is incredibly efficient, it abstracts away many OS-level details. tunkI is designed for developers who want to:
- Offload work to real OS threads: Bypass the internal Go scheduler for specialized workloads.
- Experiment with C-orchestrated parallelism: Use pthreads directly for task execution.
- Understand the Go-C bridge: Learn how to safely pass data and functions between memory-managed and raw memory environments.
tunkI uses a hybrid architecture:
- Go Layer: Handles task definition, scheduling logic, and high-level interface.
- C Layer: Implements a thread-safe circular task queue, worker thread pools (pthreads), and low-level synchronization primitives.
- Bridge Layer: A unique "Ticket Registry" system that ensures memory safety by mapping Go objects to stable integer IDs, preventing cgo pointer panics during Garbage Collection cycles.
- Hybrid Scheduling: Go defines the "what", C decides the "when" and "where".
- Real Worker Pools: Configurable number of OS threads for true parallel execution.
- CSP Channels: Implementation of Communicating Sequential Processes pattern using C-managed blocking queues.
- Wait Synchronization: Built-in mechanism to block the main thread until all distributed tasks have finished.
- Memory Safety: Advanced registry pattern to safely bridge Go objects to C worker threads.
- Go 1.18+
- GCC or another C compiler
pthreadlibrary (typically present on Linux/macOS)
package main
import (
"fmt"
"github.com/YacineMK/tunkI"
)
func main() {
// 1. Initialize with 4 worker threads
s := tunkI.NewScheduler(tunkI.Config{
Workers: 4,
})
// 2. Start the C worker pool
s.Run()
// 3. Schedule work
s.Schedule(tunkI.Task{
Id: 1,
Function: func() {
fmt.Println("This is running on a real C thread!")
},
})
// 4. Wait for completion
s.Wait()
}We provide several standalone examples to help you get started:
- Basic Creation: The simplest way to get a task running.
- Wait Synchronization: How to coordinate multiple concurrent tasks.
- CSP Channels: Communication between producer and consumer tasks via safe channels.
