Skip to content

YacineMK/tunkI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tunkI

tunkI Logo

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.

🚀 Why tunkI?

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.

🏗️ Architecture

tunkI uses a hybrid architecture:

  1. Go Layer: Handles task definition, scheduling logic, and high-level interface.
  2. C Layer: Implements a thread-safe circular task queue, worker thread pools (pthreads), and low-level synchronization primitives.
  3. 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.

✨ Core Features

  • 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.

📦 Getting Started

Prerequisites

  • Go 1.18+
  • GCC or another C compiler
  • pthread library (typically present on Linux/macOS)

Basic Usage

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()
}

📚 Examples

We provide several standalone examples to help you get started:

About

Hybrid Go/C scheduler with real OS threads, queues, and channels for running Go tasks concurrently

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors