Exam 2 Review - Chapters 4 to 6, Tutorials for Mutex Lock and Semaphore Flashcards
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.