L5-Concurrent_Data_Structures
L5-Concurrent_Data_Structures
CS3211 L3 - Synchronization 14
S1: Concurrency in the thread-safe stack
• Safe for multiple threads to call the member functions concurrently
• Exception safe
• BUT the work is serialized for the stack data structure
• only one thread is ever doing any work in the stack data structure at a time
• Serialization limits the performance of an application that exhibits
significant contention on the stack
• No means of waiting for an item to be added
• A thread must periodically call empty(), or call pop() and catch the
empty_stack exceptions
• Consume precious resources checking for data or the user must write an
external wait and notification code
• Analyze the constituent parts and associate one mutex with each
distinct item
• Insert mutexes into the data structure itself, and thus we cannot simply make
use of the STL library anymore
• Our queue
• Push (enqueue) at the back
• Pop (dequeue) from the front
Push
• Push: need to lock both front and back mutexes; • Push: front is not affected; need to lock only back
always check front==back mutex