Examples¶
This section provides practical examples demonstrating how to use cereggii's concurrent data structures effectively in real-world scenarios.
AtomicDict Examples¶
Learn how to leverage the power of lock-free dictionaries for high-performance concurrent programming.
Using reduce() for Multithreaded Aggregation¶
Learn the fundamentals of concurrent data aggregation with AtomicDict. This example demonstrates:
- How to use
reduce()for thread-safe aggregation - Performance comparison between single-threaded
dictand multithreadedAtomicDict - The benefits of specialized reduction functions like
reduce_sum() - Achieving linear speedup with multiple threads
Key concepts: Thread-safe aggregation, compare-and-set operations, specialized reduce functions
Using reduce() for Averaging¶
A more advanced example showing how to handle operations that aren't naturally commutative or associative. This example covers:
- Transforming non-commutative operations into multithreading-friendly ones
- Handling implicit contention with
ThreadHandle - Performance optimization techniques for free-threading Python
- Computing averages correctly across multiple threads
Key concepts: Commutative operations, thread-local handles, avoiding shared object contention
Getting Started¶
If you're new to concurrent programming with cereggii, we recommend:
- Start with the reduce() example to understand the basics
- Progress to the averaging example for advanced techniques
- Explore the API Reference for detailed documentation
Contributing Examples¶
Have a great example demonstrating cereggii's capabilities? Contributions are welcome! Visit the cereggii repository to submit your examples.