Quiz 7 Flashcards
What is thread local storage?
The stack of a thread
Spinlocks work quite well on multi-CPU systems
True
in programming, a race condition is an error that happens when a program finishes early than expected.
(true or false)
False
When using POSIX threads, what is the correct way to initiate a new thread?
pthread_start()
pthread_create()
pthread_run()
pthread_init()
pthread_create()
Does pthread_create() return anything?
No, because pthread_create() is not a function
Yes, but only on failure
Yes, it always return an integer value
No, because after it executes the content of the text segment is overwritten
Yes, it always return an integer value
What is a thread?
Just another name for process
A parallel algorithm
A library to enable process to communicate
A multiprogramming abstraction within a single process
A multiprogramming abstraction within a single process
A test-and- ______ instruction returns the old value of a variable while simultaneously updating it to a new value
set
The code below is correct
pthread_mutex_t lock;
pthread_mutex_lock(&lock);
x = x + 1;
pthread_mutex_unlock(&lock);
False
Multiple threads within a process can share data
True False
True
What is the code below doing?
pthread_mutex_lock(&lock);
balance = balance + 1;
pthread_mutex_unlock(&lock);
Choices:
Creating a new thread and waiting for it to terminate
Using a lock to protect a critical section
Measuring how many times the thread loops while waiting to acquire the lock
Freeing the memory used to create a lock
Using a lock to protect a critical section
Threads allow to parallelize computation within a single process
True
What is a critical section?
Choices
A sequence of instructions which is likely to crash a program
A piece of code that must not be executed concurrently by more than one thread
A data structure used for communication between threads
Another name for thread
A piece of code that must not be executed concurrently by more than one thread
Interrupting an atomic instruction does not leave the CPU in an undefined state
(true or false)
true
One way to implement critical sections on a single-processor system is to simply disable interrupt. Is this approach practical?
Choices:
No, because there is no way to disable interrupts on such a system
Yes, because it is so simple that it is impossible to get it wrong
No, because it gives threads too many privileges (the ability to disable interrupt)
Yes, because it can be performed efficiently
No, because it gives threads too many privileges (the ability to disable interrupt)
What are the criteria used to judge the quality of a lock implementation? Select all that applies
Correctness
Performance
Fairness
Obsolescence
Correctness
Performance
Fairness