https://github.com/lukaofirst/parallel-programming-dotnet
This repository contains all my practices and lessons about Parallel Programming in .NET
https://github.com/lukaofirst/parallel-programming-dotnet
concurrency concurrent-collections concurrent-dictionary concurrent-queue concurrent-stack dotnet dotnet-core lock multithreading mutex parallel-programming parallelism plinq threadsafe
Last synced: 3 months ago
JSON representation
This repository contains all my practices and lessons about Parallel Programming in .NET
- Host: GitHub
- URL: https://github.com/lukaofirst/parallel-programming-dotnet
- Owner: lukaofirst
- Created: 2025-01-18T13:43:53.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2025-01-18T13:51:41.000Z (5 months ago)
- Last Synced: 2025-01-18T15:04:55.285Z (5 months ago)
- Topics: concurrency, concurrent-collections, concurrent-dictionary, concurrent-queue, concurrent-stack, dotnet, dotnet-core, lock, multithreading, mutex, parallel-programming, parallelism, plinq, threadsafe
- Language: C#
- Homepage:
- Size: 23.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Parallel Programming in .NET
This repository provides examples and exercises on parallel programming in .NET, covering synchronization mechanisms, concurrent collections, task coordination, parallel loops, and Parallel LINQ.
- Main Topics Learned
- **Concurrency != Parallelism**:
- **Concurrency**: It's the capacity to handle multiple tasks at once
- **Parallelism**: It's the capacity to execute multiple tasks at once
- **Concurrency Synchronization**: Covers different synchronization mechanisms to manage concurrent access to shared resources
- **Concurrent Collections**: Covers the usage of thread-safe collections
- **Task Coordination**: Covers different techniques to coordinate tasks
- **Parallel Loops**: Covers the use of parallel loops to perform parallel operations on collections
- **Parallel LINQ**: Covers the usage of PLINQ (Parallel LINQ) to perform parallel operations on collections
- **Topics in Details**
- **Concurrency Synchronization**
- **LockSync**: Demonstrates the use of `lock` statement to synchronize access to a shared resource.
- **Interlocked**: Shows how to use `Interlocked` class for atomic operations on shared variables.
- **SpinLockSync**: Explains the use of `SpinLock` for low-level synchronization.
- **MutexSync**: Demonstrates the use of `Mutex` for inter-process synchronization.
- **ReaderWriterLockSync**: Shows how to use `ReaderWriterLockSlim` to allow multiple readers or exclusive access to a resource.
- **Concurrent Collections**
- **ListAndConcurrentBag**: Compares the use of `List` with locks and `ConcurrentBag` for thread-safe operations.
- **DictionaryAndConcurrentDictionary**: Compares the use of `Dictionary` with locks and `ConcurrentDictionary` for thread-safe operations.
- **QueueAndConcurrentQueue**: Compares the use of `Queue` with locks and `ConcurrentQueue` for thread-safe operations.
- **StackAndConcurrentStack**: Compares the use of `Stack` with locks and `ConcurrentStack` for thread-safe operations.
- **Task Coordination**
- **Task Continuation**: Demonstrates how to chain tasks using continuations.
- **Child Tasks**: Shows how to create and manage child tasks.
- **Barrier**: Explains the use of `Barrier` to synchronize multiple tasks at a specific point.
- **Countdown Event**: Demonstrates the use of `CountdownEvent` to wait for multiple tasks to signal completion.
- **Reset Event**: Shows how to use `ManualResetEventSlim` for signaling between tasks.
- **Semaphore**: Demonstrates the use of `SemaphoreSlim` to limit the number of concurrent tasks.
- **Parallel Loops**
- **Parallel Invoke**: Demonstrates the use of `Parallel.Invoke` to run multiple actions in parallel.
- **ForEach and ForEachAsync**: Shows how to use `Parallel.ForEach` and `Parallel.ForEachAsync` for parallel iteration over collections.
- **For and ForAsync**: Demonstrates the use of `Parallel.For` and `Parallel.ForAsync` for parallel iteration with indices.
- **Thread Local Storage**: Explains the use of thread-local storage in parallel loops.
- **Partitioning**: Shows how to partition data for parallel processing.
- **Handling Exceptions**: Demonstrates how to handle exceptions in parallel loops.
- **Parallel LINQ**
- **AsParallel**: Demonstrates the use of `AsParallel` to enable parallel processing of LINQ queries.
- **ParallelQuery**: Shows how to create and use `ParallelQuery` for parallel LINQ operations.
- **Handling Cancellations and Exceptions**: Explains how to handle cancellations and exceptions in PLINQ queries.
- **Merge Options**: Demonstrates the use of merge options to control the buffering behavior of PLINQ queries.
- **Custom Aggregations**: Shows how to perform custom aggregations in PLINQ queries.