Massively Parallel Systems Synchronization

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

Why is synchronization crucial when multiple agents access a shared hardware resource?

Synchronization ensures that only one agent can use the resource at a time, preventing conflicts and data corruption.

What is the fundamental problem in computer architecture and operating systems related to shared variables?

Updating a shared variable, which indicates whether a resource is busy or not, is a critical and fundamental problem.

Define what a critical section is in the context of synchronization.

A critical section is a section of code that accesses a shared resource that must not be accessed concurrently by more than one thread.

Why is disabling interrupts not a viable solution for synchronization in multicore systems?

<p>Disabling interrupts is futile in multicore systems. Threads execute in parallel in different thread contexts, thus disabling interrupts on one core does not prevent other cores from accessing shared data.</p> Signup and view all the answers

Explain the purpose of a lock in the context of synchronization.

<p>A lock is a primitive that protects critical sections, ensuring that only one thread can access the shared resource at a time.</p> Signup and view all the answers

What issue can arise when implementing locks using simple loads and stores to shared memory flags?

<p>Using only loads and stores can lead to a deadlock.</p> Signup and view all the answers

Explain why a simple software lock using loads and stores is not an atomic solution.

<p>Because two threads can acquire the lock at the same time.</p> Signup and view all the answers

What is the key characteristic of atomic read-modify-write (RMW) instructions that makes them suitable for synchronization?

<p>RMW instructions read a value from memory, modifies it, and then writes it back to memory atomically.</p> Signup and view all the answers

Describe how the Test-and-Set (T&S) instruction works and its purpose in synchronization.

<p>T&amp;S reads the lock value, writes 1 to the lock (atomically), and returns the original lock value. It's purpose is to acquire a lock.</p> Signup and view all the answers

What problem can arise from repeatedly executing T&S in a loop when locks are cacheable?

<p>Looping may generate a lot of bus traffic.</p> Signup and view all the answers

What is the purpose of using exponential back-off with T&S, and how does it help reduce bus traffic?

<p>The purpose is to reduce the frequency of T&amp;S by retrying after a pause. Back-off delay is $k \times c^i$ at _i_th trail.</p> Signup and view all the answers

How does the 'test and test&set' approach improve upon the basic 'test and set' lock?

<p>The approach reduces bus traffic because it works well with cache.</p> Signup and view all the answers

In the context of atomic operations, what does 'atomic swap' do?

<p>Atomic swap exchanges value in register for value in memory.</p> Signup and view all the answers

What is the purpose of the Compare-and-Swap (CAS) instruction, and where is it useful?

<p>Compare-and-swap swaps value in register with value in memory if condition is met, which is useful to implement atomic queue insertions/removals.</p> Signup and view all the answers

Explain what 'Fetch-and-Increment' does in atomic operations.

<p>Fetch-and-increment returns value of a memory location and atomically increments it.</p> Signup and view all the answers

Why are Load-Locked/Store-Conditional (LL/SC) instructions preferred over RMW instructions in RISC pipelines?

<p>LL/SC can use separate Load and Store provided hardware checks that there was no intervening Store.</p> Signup and view all the answers

Describe how Load-Locked (LL) and Store-Conditional (SC) instructions work together to achieve atomic operations and what happens when the 'link' is invalidated.

<p>LL reads a value and marks the memory location as linked. SC attempts to write a new value only if the link is still valid. If the link was invalidated, SC fails, and no write happens.</p> Signup and view all the answers

State two advantages of using LL/SC instructions, instead of other methods.

<p>Easier to implement in pipeline and versatile RMW primitives can be implemented by changing code between LL and SC.</p> Signup and view all the answers

What is a barrier in the context of thread synchronization, and what purpose does it serve?

<p>A barrier is a synchronization protocol amongst multiple threads, and all threads must reach barrier before any thread is allowed to continue.</p> Signup and view all the answers

When implementing a barrier using a shared counter, why must the increment of the counter be protected by a lock?

<p>The increment of the counter must be protected by a lock to avoid race conditions and ensure that each thread's increment is atomically recorded.</p> Signup and view all the answers

What are semaphores and give the names of their two operations

<p>Semaphores can be built on top of RMW instructions, and are integer variable with two operations: pakken and vrijgeven.</p> Signup and view all the answers

Describe two methods used when implementing semaphores.

<p>The semaphore can be implemented using busy waiting or by blocking thread.</p> Signup and view all the answers

Name two main disadvantages of using the 'busy waiting' method with semaphores.

<p>busy waiting has a low overhead but holds processor, and may have high memory/network traffic</p> Signup and view all the answers

Name two main advantages of using the 'blocking' method with semaphores.

<p>With blocking, calling thread is descheduled allowing processor to work on something else.</p> Signup and view all the answers

Define the term 'race condition' and provide a simple scenario where it might occur in a multithreaded program.

<p>A race condition occurs when the outcome of a program depends on the unpredictable order in which multiple threads access shared resources. A race condition may occur in a system with credit and debit threads.</p> Signup and view all the answers

In the context of thread synchronization, explain the concept of 'mutual exclusion' and why it is important.

<p>Mutual exclusion ensures that only one thread can access a shared resource at any one time. Threads wishing to access a shared writable variable must do so under mutual exclusion.</p> Signup and view all the answers

Briefly outline the steps a thread typically takes to acquire a lock, access a critical section, and release the lock. What is likely to happen if a lock is not released?

<p>A thread tries to acquire a lock, if successfull it enters the critical section, then releases the lock when done. Not releasing the lock causes deadlock for any other waiting thread</p> Signup and view all the answers

Explain why an 'incorrect solution to a critical section problem' can lead to a deadlock.

<p>Code may be incorrect because contains possible deadlock.</p> Signup and view all the answers

Why should you use atomic operations when implementing lock and unlock?

<p>Implementation is incorrect otherwise, and 2 threads can acquire lock at same time</p> Signup and view all the answers

When implementing a lock algorithm, what condition causes a test&set lock to loop, potentially generating a lot of bus traffic?

<p>When locks are cacheable. Each processor is waiting for the other processor to release the lock.</p> Signup and view all the answers

What happens to threads that are waiting for a lock that is set and is yet to be released?

<p>Threads must wait until the lock is released.</p> Signup and view all the answers

How do Load-Locked (LL) and Store-Conditional (SC) instructions facilitate the implementation of atomic operations, and what is the significance of the 'linked' state?

<p>LL reads a value and marks the memory location as 'linked'. SC attempts to write only if the 'link' is valid. The linked state indicates that no other write has occurred since the LL.</p> Signup and view all the answers

Why must care be taken when including code between LL and SC?

<p>May not use instructions that cannot be undone, instructions that can cause exceptions.</p> Signup and view all the answers

When a thread tries to acquire a lock that is already held, what are two waiting options available to the thread?

<p>Busy waiting, or blocking thread.</p> Signup and view all the answers

Under what scenario is 'busy waiting' better than 'blocking' for semaphores?

<p>Busy waiting better when scheduling overhead larger than expected wait time, or no other thread to run.</p> Signup and view all the answers

What negative consequences can result from race conditions?

<p>If balance=1000 initially, credit=200, debit=100, outcome can be 1200 (you happy), 900 (bank happy), 1100 (correct)</p> Signup and view all the answers

What can cause high memory/network traffic when using busy waiting semaphores?

<p>High memory/network traffic when the waiting thread repeatedly tests a location until its value changes.</p> Signup and view all the answers

Explain when time-shared uniprocessor can solve for critical sections and how it does so.

<p>On time-shared uniprocessor system (software multithreading) with single context, critical sections may be solved by disabling interrupts.</p> Signup and view all the answers

Why is synchronization needed in both time-shared uniprocessors and multiprocessors systems

<p>Updating this shared variable is a critical and fundamental problem in computer architecture and operating systems.</p> Signup and view all the answers

Flashcards

What is Synchronization?

Ensuring that multiple threads or processes coordinate to access shared resources safely and prevent conflicts.

What is a Race Condition?

Circumstance when multiple threads or processes access and modify shared data concurrently, leading to unpredictable or incorrect results.

What is a Critical Section?

A section of code that accesses a shared resource and must not be executed concurrently by multiple threads.

What is Mutual exclusion?

A method to ensure that only one process or thread can access a critical section at any given time.

Signup and view all the flashcards

What is a Lock?

A primitive used to protect critical sections by allowing only one thread to acquire it at a time.

Signup and view all the flashcards

What are Read-Modify-Write Instructions?

A type of instruction that reads a value from memory, modifies it, and writes the modified value back to memory in a single atomic operation.

Signup and view all the flashcards

What is Test-and-Set?

An RMW instruction that reads the value of a memory location, sets it to 1, and returns the original value.

Signup and view all the flashcards

What are Load-Locked/Store-Conditional Instructions?

A pair of instructions used to implement atomic operations by loading a value and conditionally storing a new value only if the memory location hasn't been modified since the load.

Signup and view all the flashcards

What is Barrier Synchronization?

A synchronization point where all threads or processes must wait until every thread has reached it before any can proceed.

Signup and view all the flashcards

What is Blocking

A signaling mechanism where a thread that needs to wait is descheduled, allowing the processor to work on something else.

Signup and view all the flashcards

What is Busy Waiting?

A method where a waiting thread repeatedly tests a location until its value changes.

Signup and view all the flashcards

What happens in Blocking Thread?

If a thread is waiting for a resource, the thread is descheduled and allows processing for other threads.

Signup and view all the flashcards

What happens in Busy Waiting?

If a thread is waiting for a resource, the thread repeatedly tests a location until the condition for a recourse is available.

Signup and view all the flashcards

What is a semaphore?

A special variable used for controlling access to a shared resource by multiple processes or threads.

Signup and view all the flashcards

What is Spinlock?

A type of software lock where a thread continues to execute in a tight loop, repeatedly checking if the lock is available

Signup and view all the flashcards

Study Notes

  • The topic is synchronization in massively parallel systems, covering synchronization problems, solutions, and primitives.

Synchronization

  • When multiple agents access a shared hardware resource, only one agent can use the resource at a time to avoid conflicts.
  • Synchronization is a computing problem dating back to multitasking operating systems.
  • Reliable synchronization between threads or processes transcends memory coherence.
  • Shared variables indicate if a resource is busy.
  • Updating shared variables is a fundamental problem in computer architecture and operating systems.

Synchronization Problem on Uniprocessors

  • Threads accessing a shared writable variable must do so under mutual exclusion, where only one process can access the variable at any one time.
  • A race condition occurs when the outcome depends on the order of access.

Synchronization Problem on Multiprocessors

  • Threads may run concurrently, requiring program statements to appear atomic or use mutual exclusion to prevent overlapping in time.

Critical Section

  • Mutual exclusion is solved by critical sections
  • Critical sections of code access shared resources and cannot be accessed concurrently by more than one thread.

Effects of Race Conditions

  • Failures with the Therac-25 radiation therapy machine.
  • The 2003 North American Blackout which affected millions.

Disabling Interrupts

  • Disabling interrupts can solve critical sections on time-shared uniprocessor systems with a single context.
  • Disabling interrupts is ineffective in multicore systems or hardware multithreaded cores, as threads execute in parallel.

Locks

  • Locks are synchronization primitives that protect critical sections.
  • A value of 0 indicates lock is free.
  • A value of 1 (or any non-zero value) indicates lock is set.
  • To acquire a lock, a thread sets it to 1.
  • To release a lock, a thread sets it to 0.
  • While a lock is set, threads must wait until it is released.
  • Direct implementation of locks via loads and stores to shared memory can lead to deadlock.

Simple Software Lock

  • Simple software locks are described using assembly-like instructions.
  • Simple software lock is not atomic, multiple threads can acquire the lock at the same time.

Read-Modify-Write (RMW) Instructions

  • RMW instructions read a value from memory, modify it, and write it back atomically.
  • RMW instructions can return success or failure.
  • Modern ISAs have atomic RMW instructions.

Test-And-Set (T&S)

  • Assembly-like operation for test and set is shown.
  • Sets a lock to 1 atomically, returning the old value.
  • If locks are cacheable, executing T&S in a loop generates bus traffic.

Optimizing T&S

  • Frequency of Ts&S can be reduced with back-off pauses.
  • Exponential back-off delay is k x c at ith trial.
  • Test with ordinary loads - when value is 0, try to obtain lock with T&S.
  • The Test and test&set method works well with cache reduces bus traffic

Atomic Swap

  • Instructions exchange a value in a register for a value in memory.

Compare-And-Swap

  • Instructions swap a value in register with a value in memory if a condition is met.
  • They are useful for implementing atomic queue insertions/removals.

Fetch-And-Increment

  • Fetches and returns a value in memory, then atomically increments it.
  • If the value returned is 0 synchronization variable is free, otherwise synchronization variable is locked

Load-Locked and Store-Conditional (LL/SC)

  • LL/SC do not fit well in RISC pipeline or OoO processor because require atomic execution of two memory accesses
  • LL Rx, lv reads memory [lv] into register Rx.
  • SC Ry, lv tries to store Ry in memory [lv], succeeds if no other thread has written to lv since LL.
  • LL reads a value from memory and marks that location as "linked.”
  • SC attempts to write a new value to the memory location only if the "link" is still valid.
  • Sequence LL-SC was atomic.
  • Fancier atomic operations can be implemented by adding code between LL and SC.

Advantages of LL and SC

  • Easier to implement in pipeline.
  • Flexible and versatile RMW primitives can be implemented by changing code between LL and SC.

Implementation of LL/SC

  • Bus interface supports LL-bit and lock address register
  • LL-bit also cleared when lock variable ejected from cache and on context switches
  • Having multiple LL-bits and lock address registers solves several locks!

LL/SC vs. Traditional RMW

  • RMW instructions combine read and write into one atomic operation.
  • LL/SC are two separate instructions, giving more flexibility.
  • LL/SC is more like a flexible "building block" for atomic operations.

Barrier Synchronization

  • A barrier is a synchronization protocol amongst multiple threads.
  • All threads must reach barrier before any thread is allowed to continue

Semaphores

  • Semaphores (Dijkstra) are higher-level synchronization primitives built on top of RMW instructions.
  • Semaphores are integer variables with two operations, P (acquire) and V (release).
  • P decrements if sem >0, else waits; V increments to release.
  • Can be implemented via busy or blocking waiting.

Blocking vs. Busy Waiting

  • Blocking: calling thread scheduled out, high overhead, processor works on something else.
  • Busy waiting: Waiting thread repeatedly tests a location until its value changes.
  • Busy waiting is better when scheduling overhead is larger than the expected wait time and there is no other thread to run.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

More Like This

Parallel Systems and Algorithms Lecture 1
15 questions
Algoritmi Paraleli și Distribuiți
45 questions
Use Quizgecko on...
Browser
Browser