1/20
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What does each thread have its own version of?
Stack
Registers
Sigmasks
What do all threads in a process share?
Address space
Data
Code
Open files
Signal disposition (handlers)
How is thread similar to fork()?
They’re both non-blocking functions. The program continues after they’ve been executed.
What is a race condition?
When the output of concurrent threads depends on the order of operations between them. It can create non-deterministic outputs.
In the context of threads, what is instruction reordering?
Some compilers will move around items in threads to achieve peak performance. They may move simpler functions to the start and more complex ones to the end, possibly breaking threads in the process.
What is a Mutex?
A lock that we require before using a shared resource. It prevents any other thread from accessing the locked region of code. It’s released after use.
Describe the producer-consumer problem that comes with using a mutex.
If one thread is dependent on data from another and they both lock each other, something like a while loop can cause a dead lock by preventing either thread from accessing their data due to one of the locks being active. The consumer can’t consume if the producer is locked.
How do we fix the producer-consumer problem?
By using a condition variable.
What is a condition variable? What does it do?
A queue of all the waiting threads with a lock for access to the critical section of code. It essentially sends a notification to a thread alerting it that it can access that section now and likely safely lock itself.
What does declaring a condition variable look like (In C and C++)? Assume there is some unique_lock named ul and some pthread mutex named m.
pthread_mutex_lock lock;
pthread_cond_wait(&cond, &lock)
std::condition_variable cond;
cond.wait(ul, []{ return (condition); });
What is a Semaphore?
A non-negative integer variable shared among multiple processes. It acts in a similar function to wait() and lock() with more simplicity.
What is the difference between wait() and post()?
wait() waits until the value is positive and then decrements it by 1. post() increments the value by 1, possibly waking up a thread.
What happens if a wait and a post happen at functionally the same time?
No different from what would happen otherwise. The post() is picked up regardless.
What is a Binary Semaphore?
A Semaphore that starts at 1. This allows the first wait to decrement the value to effectively “lock” the code that is critical.
Do the order that the posts and waits happen in matter?
Only the order of waits matters, because it can cause deadlocks. The order of posts only affects the scheduling efficiency.
When dealing with scheduling constraints between threads, why do we have an initial value of 0 for our Semaphore?
Because it allows for another thread to wait for a “signal” (post) from the other. The post() would increment that value, allowing the wait to finally decrement since the Semaphore is no longer 0.
What does the Application layer do, and what are the key terms?
Meaning of data for the program. HTTP, DNS.
What does the Transport layer do, and what are the key terms?
End-to-end process communication. TCP, UDP, ports.
What does the Network layer do, and what are the key terms?
Host-to-host addressing and routing. IP, routers, packets.
What does the Data Link layer do, and what are the key terms?
Local delivery on current link segment. Ethernet, Wifi, MAC, frames.
What does the Physical layer do, and what are the key terms?
Raw bits onto wire/fiber/radio. Electrical signals, bits.