You are on page 1of 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