0% found this document useful (0 votes)
16 views13 pages

Lec18-Lock Based Concurrent Data Structures

The document discusses various lock-based concurrent data structures including concurrent counters, linked lists, queues, and hash tables. It explains that adding locks to a data structure makes it thread-safe but how the locks are implemented determines correctness and performance. Concurrent counters can scale poorly due to lock overhead, so approximate counters that batch updates are more efficient. Concurrent linked lists use a per-list lock while queues employ separate head and tail locks. Concurrent hash tables are made from concurrent linked lists with one lock per hash bucket. In summary, careful lock usage is needed for correctness and more concurrency does not always improve performance.

Uploaded by

razi haider
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)
16 views13 pages

Lec18-Lock Based Concurrent Data Structures

The document discusses various lock-based concurrent data structures including concurrent counters, linked lists, queues, and hash tables. It explains that adding locks to a data structure makes it thread-safe but how the locks are implemented determines correctness and performance. Concurrent counters can scale poorly due to lock overhead, so approximate counters that batch updates are more efficient. Concurrent linked lists use a per-list lock while queues employ separate head and tail locks. Concurrent hash tables are made from concurrent linked lists with one lock per hash bucket. In summary, careful lock usage is needed for correctness and more concurrency does not always improve performance.

Uploaded by

razi haider
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/ 13

Operating System (OS)

CS232
Concurrency: Lock-based Concurrent Data Structures

Dr. Muhammad Mobeen Movania


Dr Muhammad Saeed
Outlines
• What is thread safety of a data structure?
• Concurrent Counter
• Issues and resolution of Concurrent Counter
• Concurrent Linked Lists
• Concurrent Queues
• Concurrent Hash Tables
• Summary
What is thread safety?
• Adding locks to a data structure to make it
usable by multiple threads concurrently
makes the data structure thread safe
• How locks are added determines correctness
and performance of the data structure
• Many different data structures exist, simplest
is a concurrent counter
Concurrent Counter
• Simple counter without locks is not thread
safe
Concurrent Counter (2)
• Counter with lock is thread safe
Concurrent Counter (3)
• Performance of
concurrent counter
scales poorly
– Locks add additional
overhead which
reduces performance
• Solution
– Use approximate
counters which update
counter value after
some threshold S so the
lock is accessed S times
Approximate Counter
• Performance of approximate counter with
varying values of S
Concurrent Linked List
• Per-list lock which is acquired when needed
Concurrent Linked List (2)
• Insert Function: Malloc call could be moved
out of lock to avoid branching
Concurrent Queues
• Implemented using two locks: head and tail
locks (to provide concurrency in enqueue and
dequeuer operations)
Concurrent Queues (2)
• Enqueue and Dequeue operations
Concurrent Hash Table
• Made using concurrent linked list
• Uses one lock per hash bucket each
represented by a list
Summary
• We introduced a sampling of concurrent data
structures, from counters, to lists and queues,
and finally to the ubiquitous and heavily used
hash table
• We must be careful with acquisition/release of
locks around conditional control flow
• Enabling more concurrency does not
necessarily increase performance

You might also like