12 - Shared data between threads Flashcards

1
Q

What are the characteristics of multicore CPUs?

A
  • Cores are individual processing units within a CPU.
  • Evolution from multi-processor setups with CPUs connected by a BUS.
  • First dual-core CPU by IBM in 2000; first Intel dual-core in 2006.
  • Commodity processors have fewer than 12 cores, specialized processors can have up to 100 cores.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the concept of shared memory in multiprocessors?

A
  • All memory locations are accessible to any processor.
  • The cost of memory access is constant.
  • BUS bandwidth is limited; caches help reduce data transfer.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Explain the concept of false sharing in shared memory multiprocessors.

A
  • False sharing occurs when multiple processors modify shared data, leading to frequent updates within the same cache line.
  • This results in the invalidation of entire cache lines, even for logically independent updates.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is cache coherence in the context of multicore processors?

A
  • Each core has a private cache, making data coherence essential.
  • Shared data can lead to cache misses and necessitate data copying across cores.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How can false sharing be reduced in shared memory multiprocessors?

A
  • Use private data to minimize shared data access.
  • Employ compiler optimizations to reduce memory loads and stores.
  • Pad data structures so each thread’s data resides on a different cache line.
  • Modify data structures to reduce data sharing among threads.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is hyperthreading and its benefits in CPU architecture?

A
  • Hyperthreading allows multiple threads to execute concurrently on the same core.
  • It creates virtual cores to increase efficiency.
  • First introduced by Intel in 2002 in Xeon and Pentium 4.
  • Offers performance gains by utilizing idle resources in the CPU.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the considerations for concurrent data access in threads?

A
  • Shared variables (like global variables in C) can be accessed by multiple threads.
  • Shared data should be managed carefully to avoid conflicts.
  • Accessing and modifying the same variable by different threads requires synchronization
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How does instruction ordering differ between single-threaded and multi-threaded applications?

A
  • In single-threaded applications, instruction order follows the C code sequence.
  • In multi-threaded applications, instruction order can vary, leading to different execution combinations.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a critical region in the context of thread synchronization?

A
  • A piece of code where resources are shared and should be executed by one task at a time.
  • It is delimited by read/write instructions to the shared resource.
  • Other tasks trying to enter should be blocked if a task is already inside.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the requirements for a critical region to be effective?

A
  • Mutual Exclusion: Only one task can be inside the critical region.
  • Progress: A task inside cannot block others from entering.
  • Limited Wait: A task should wait only a limited time before entering.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is mutual exclusion and its consequences in concurrent programming?

A
  • Mutual Exclusion ensures that at most one task is inside a critical region.
  • Consequences include the risk of starvation, where a task is never scheduled, and deadlock, where tasks wait indefinitely due to coding problems
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are locks in the context of thread synchronization?

A
  • Locks ensure mutual exclusion in critical sections.
  • Spin locks involve busy waiting and can be inefficient.
  • They are the simplest mechanism for mutual exclusion.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How are mutexes used in concurrent programming?

A
  • Mutexes are assigned to critical regions for synchronization.
  • They require specific calls (mutex_lock and mutex_unlock) for entering and exiting the critical region.
  • Proper usage includes minimizing the duration of the locked state.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are POSIX mutexes and their functionality?

A
  • POSIX mutexes are associated with Pthreads in programming.
  • They require initialization and specific functions for locking and unlocking.
  • Mutexes are used for mutual exclusion in multi-threaded environments.
pthread_mutex_t mux;
mux=PTHREAD_MUTEX_INITIALIZER;
int pthread_mutex_destroy(pthread_mutex_t *);
  • Mutex locking
    • int pthread_mutex_lock(pthread_mutex_t *mutex);
    • Blocks thread until resource is available/can enter critical region
    • Returns when task enters critical region
    • Returns 0 in case of success
  • Mutexes should be locked for the minimum amount of time
  • Mutex unlock
    • int pthread_mutex_unlock(pthread_mutex_t *mutex);
    • Returns 0 in case of success
    • Allow other thread to enter the critical region
    • Unblock a thread from pthread_mutex_lock
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are POSIX spin locks and their use cases?

A
  • Spin locks are low-level synchronization mechanisms suitable for short critical regions.
  • They involve the thread spinning in a loop until the lock becomes available.
  • Careful use is required to avoid excessive CPU consumption and potential deadlocks.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly