Exam 2 Review - Chapters 4 to 6, Tutorials for Mutex Lock and Semaphore Flashcards
(38 cards)
What is a thread?
A basic unit of computation, AKA a lightweight process
What do multi-threaded applications consist of?
They have multiple threads within a single process, each having their own program counter, stack, and set of registers; all share common code and data
What are the benefits of using multi-threaded processes?
Improves responsiveness, resource sharing, economy, and scalability
How do multithreading models work?
User threads are supported above the kernel, and kernel threads are supported by the OS
What are the different kinds of multithreading models?
Many-to-one, one-to-one, and many-to-many
Why is many-to-many the most popular multithreading model?
A blocking system call wouldn’t block the entire process, as well as allowing the OS to create a sufficient number of kernel threads
What is assigned to a thread when it’s created?
A thread ID, stack, and starting address for execution
What parameters does pthread_create() have?
In order, ChildID, Thread_attributes, function_name, arguments
What is the purpose of pthread_join()?
Wait for the target thread to terminate before further processing in main thread
How do you compile and create and executable file with pthread?
cc -o programName programName.c -pthread
Why do we care for process synchronization?
So processes can execute concurrently with minimal problems (OS must provide mechanisms to ensure the orderly execution of cooperating processes)
What problem arises with concurrent data access?
May result in data inconsistency
What is the Producer-Consumer (Bounded Buffer) problem?
A data buffer shared by two processes; each can update counter, risks a race condition
What is a race condition?
Several processes access and manipulate the same data concurrently and the outcome depends on the particular order of execution
What is the critical section?
It’s a segment of code in each process where the process may be changing common variables, updating table, etc.
What is Peterson’s solution for fixing the race condition?
Uses the idea of locking to protect critical regions via locks; meets the three requirements: mutual exclusion, progress, bounded waiting. Uses flags as locks
What are mutex locks?
Based on the idea of locking, protects a critical section by first acquire() a lock and then release() the lock (boolean variable indicating lock availability, and methods must be atomic); considered the simplest synchronization tools
What are semaphores?
Similar to mutex locks, binary but uses an integer value to indicate lock availability
How can you use semaphores with no busy waiting?
Instead of keeping a process busy waiting, have it block itself (suspend itself), then wake it up when a semaphore is ready
What is a deadlock?
Multiple processes are blocked, each waiting for a resource that can only be freed by one of the other blocked processes
What methods can you use to resolve deadlocks?
FIFO (every process will eventually get its turn to be removed) or LIFO (early processes may never be removed, starved)
What solutions can be used for the Dining-Philosophers Problem?
Allow at most 4 philosophers to sit at the table; pick up chopsticks only if both are available (picking up done in critical section); use asymmetric solution, odd-numbered picks up first the left then right chopstick, even-numbered picks up first right then left chopstick
What is a CPU-I/O burst cycle?
A process execution consisting of a cycle of CPU execution (performing calculations) and I/O wait (waiting for data transfer in or out the system)
What does the CPU (short-term) scheduler do?
Handle removal of running process from CPU and the selection of another process, as well as selecting from among the processes in ready
queue, and allocates the CPU to one of them