0% found this document useful (0 votes)
47 views

Concurrent Collections

This document introduces concurrent collections in .NET and discusses thread safety. It defines concurrency as supporting multiple actions in progress simultaneously, while parallelism refers to executing actions simultaneously. Concurrent collections in .NET use synchronizing mechanisms like spinning and interlocked operations to be thread safe. Blocking operations use locks to prevent erroneous behavior but can damage scalability, while non-blocking operations allow progress without impediment between threads. Lock-free programming guarantees system-wide progress without blocking, while wait-free provides stronger per-thread guarantees but is more difficult to implement.

Uploaded by

Lead Head
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Concurrent Collections

This document introduces concurrent collections in .NET and discusses thread safety. It defines concurrency as supporting multiple actions in progress simultaneously, while parallelism refers to executing actions simultaneously. Concurrent collections in .NET use synchronizing mechanisms like spinning and interlocked operations to be thread safe. Blocking operations use locks to prevent erroneous behavior but can damage scalability, while non-blocking operations allow progress without impediment between threads. Lock-free programming guarantees system-wide progress without blocking, while wait-free provides stronger per-thread guarantees but is more difficult to implement.

Uploaded by

Lead Head
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Introduction

to Concurrent
Collections
A D E N H A R R I S N 10 2 3 57 2 8
Concurrent Vs Parallel programs
“A system is said to be concurrent if it can support two or more actions in progress at the same time. A system is said to
be parallel if it can support two or more actions executing simultaneously.” – The Art of Concurrency by Clay Breshears

https://techdifferences.com/difference-between-concurrency-and-parallelism.html
Concurrent Collections in .NET
and Thread Safety
Thread Safety:
A piece of code is considered thread
safe if when ran simultaneously by
multiple threads it still functions
correctly.

To be thread safe, .NET concurrent


collections use a combination of
synchronising mechanisms
‘Spinning’(blocking) and
‘Interlocked’(non-blocking) operations.
Concurrent Progress Conditions
Blocking: Non-Blocking:
Uses Locks to sync access to shared resources and stop erroneous
behaviour by preventing critical code from being executed Should a thread fail or be suspended it won’t imped other threads.
concurrently.
Often more useful when improving multi-core processor
performance
While a thread is blocked it can’t make progress.
The simplicity of programming locks comes at the expense of
damaging scalability by forming bottlenecks Non-blocking

Code can be more challenging to paralyze effectively


Lock-Free
Has to consider:
Race conditions
Deadlocks Wait-Free
Simplicity vs scalability
Lock-Free and Wait-Free
Lock Free Wait Free
guaranteed system-wide progress guaranteed per-thread progress
Reduces blocking in algorithms and data Stronger progress guarantee
structures
Writing a correct lock-free program is Harder to design and implement
challenging
Isn’t wait free Is also lock free

“Lock-free programming is like playing with knives”


- Herb Sutter
Closing
Thoughts

You might also like