Single-Threaded Execution Model

AutoLang is designed with a steadfast philosophy: Strict Single-Threaded Execution. This decision is not a limitation, but a strategic feature to optimize performance for Embedded Systems, Build Tools, and Scripting.


1. The Embedded Reality

Hardware Constraint: Single-Core Chips

A primary target for AutoLang is embedded hardware (microcontrollers, IoT devices). Many of these chips (e.g., ARM Cortex-M0/M3, AVR, ESP8266) contain only a single CPU core.

On such hardware, "multi-threading" is an illusion created by the OS scheduler via Time Slicing. This requires saving and restoring CPU registers hundreds of times per second (Context Switching).

The Problem: This simulation wastes valuable CPU cycles and battery power just to manage threads, rather than executing your actual code.
The Solution: AutoLang runs on a single thread, effectively "owning" the CPU without the overhead of a complex scheduler.

2. Zero Locking Overhead

By guaranteeing single-threaded execution, AutoLang removes entire classes of runtime overhead found in languages like Java, C#, or Go.

  • No Locks (Mutex/Semaphores): The VM never needs to pause execution to wait for a resource to be free.
  • No Atomic Operations: Variable increments and memory access are simple CPU instructions, not expensive atomic bus-locking operations.
  • CPU Cache Locality: Since one thread processes data sequentially, the CPU cache remains hot and valid. In multi-threaded systems, threads constantly invalidate each other's cache lines.

3. Comparison: Threading Models

MetricMulti-threaded (Java/C++)AutoLang (Single-Threaded)
Single-Core HardwareHigh Overhead (Context Switching)Native Speed (No Overhead)
Memory AccessRequires SynchronizationDirect & Instant
DeadlocksPossible & CommonImpossible
DeterminismUnpredictable (Race Conditions)100% Deterministic

Impact on Developer Experience

Similar to JavaScript (Node.js), this model simplifies logic. You don't need to worry about race conditions corrupting your data. If you need concurrency (e.g., waiting for IO), AutoLang handles it via an Event Loop or async mechanisms (future), keeping the main thread free.

// In AutoLang, you never write code like this: // synchronized(lock) { ... } // Instead, you just write logic: var counter = 0 func update() { counter = counter + 1 // Guaranteed safe, even in async contexts }