Skip to content

๐Ÿงต ThreadFactory v1.5.2 โ€“ Massive Concurrency Upgrade

Latest
Compare
Choose a tag to compare
@Synaptic724 Synaptic724 released this 11 Jul 22:24

This release marks a significant evolution of ThreadFactory, introducing a modular and powerful concurrency stack built from first principles. The entire system has been refactored into high-performance primitives, orchestrators, dispatchers, sync types, and thread tools, providing granular control and unprecedented performance for No-GIL Python applications.


๐Ÿš€ What's New

๐Ÿ”’ Sync Types โ€“ concurrency.sync_types

Thread-safe wrappers for Pythonโ€™s core data types, designed for deterministic, low-contention concurrent access. These are now reference types and should be used with care.

  • SyncInt: Atomic integer with full arithmetic and bitwise support.
  • SyncBool: Thread-safe boolean with complete logical operation support.
  • SyncString: A mutable, thread-safe wrapper for strings.
  • SyncFloat: Atomic float with full arithmetic support.
  • SyncRef: An atomic, thread-safe reference to any object, enabling safe read/write access and conditional updates.

๐Ÿง  New Primitives โ€“ synchronization.primitives

A suite of low-level building blocks for sophisticated synchronization patterns.

  • Dynaphore: A dynamically resizable permit gate, ideal for adaptive queues and elastic thread pools.
  • FlowRegulator: A smart semaphore with factory ID targeting and callback routing, perfect for agentic workers.
  • SmartCondition: An advanced Condition alternative that allows targeted wakeups and ULID tracking.
  • TransitCondition: A minimalist and lightweight wait/notify condition with FIFO-safe callbacks.
  • SignalLatch: A latch with observer signaling that can notify a controller before blocking.
  • Latch: A classic, reusable latch that releases all threads permanently once opened.

โšก New Coordinators โ€“ synchronization.orchestrators

High-level tools for managing complex thread workflows.

  • TransitBarrier: A reusable barrier with threshold coordination and an optional callable execution.
  • SignalBarrier: A signal-based barrier supporting thresholds, timeouts, and failure states.
  • ClockBarrier: A time-sensitive barrier that fails if threads do not arrive before a global timeout.
  • Conductor: A reusable group synchronizer that executes tasks after a thread threshold is met.
  • MultiConductor: Manages multiple groups with per-group tasks and a global thread threshold, supporting lock-step, forked, and synchronized forked execution.
  • Scout: A predicate-based monitor that blocks one thread while evaluating a condition with a timeout.

๐Ÿš‰ New Execution Gates โ€“ synchronization.execution

  • BypassConductor: Allows a fixed number of threads (N) to execute a callable pipeline, capturing results via an Outcome. It's perfect for controlled bootstraps or one-time initializers.

๐ŸŽ› New Dispatchers โ€“ synchronization.dispatchers

Advanced tools for routing threads to callables.

  • Fork: Assigns callables based on usage caps, ensuring each executes a fixed number of times.
  • SignalFork: Routes threads to callables immediately on arrival and notifies a controller when all slots are consumed.
  • SyncFork: Coordinates N threads into callable groups that execute simultaneously once all slots are filled.
  • SyncSignalFork: Extends SyncFork with the ability to execute a callable as a signal.

๐ŸŽฎ New Controller โ€“ synchronization.controller

  • SignalController: A central registry for managing the lifecycle of concurrency objects. It supports registration, invocation with hooks, event notification, and a thread-safe dispose() method for recursively tearing down all managed objects.

โฑ๏ธ New Utilities

  • AutoResetTimer (thread_factory.utils.timing): A timer that automatically resets, useful for cyclic backoffs and heartbeats.
  • Stopwatch (thread_factory.utils.timing): A simple nanosecond-precision profiler for performance tracking.
  • Package (thread_factory.utils.coordination.package): A thread-safe, delegate-style wrapper for callables.

โœ… Structural and Performance Improvements

  • __slots__ Adoption: All concurrency classes now use __slots__, resulting in a reduced memory footprint, faster attribute access, and less garbage collector churn under high load.
  • New Folder Structure: The synchronization module is now organized by purpose, improving clarity and maintainability:
    • primitives/: Low-level synchronization building blocks.
    • orchestrators/: Group coordination and flow control.
    • dispatchers/: Thread-callable routing logic.
    • execution/: Execution gates and work-limited runners.
    • controller/: Lifecycle and command management.
  • Queue and Stack Enhancements:
    • ConcurrentQueue and ConcurrentStack now feature an is_empty() method for graceful shutdown checks and batch_steal() for optimized consumer loops.

โ— Important Changes & Renaming

To improve clarity and consistency across the new modular architecture, the following classes have been renamed:

  • ActionBarrier is now TransitBarrier.
  • SignalCondition is now TransitCondition.

๐Ÿ“Œ Developer Notes

  • For modern worker-oriented designs, prefer using FlowRegulator combined with SmartCondition.
  • When implementing fork-like behaviors, use the new Fork or SyncFork dispatchers.
  • For performance instrumentation, adopt Stopwatch and AutoResetTimer.
  • Use SignalCondition for simple signaling needs and SmartCondition for targeted, complex scenarios.
  • Leverage ConcurrentQueue.is_empty() to manage graceful shutdowns in your worker threads.

Thank you for using ThreadFactory! We believe this massive upgrade will unlock new levels of performance and control in your concurrent applications.

Full Changelog: v1.2.4...v1.5.0