1/33
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
what components do threads share?
code, heap, global/static variables, and file descriptors
what do threads not share?
registers, stack, and TCB
what is stored in each TCB:
thread id, state, priority, used register, stack location and pointer, local variables, program counter
what is a thread?
a unit of execution within a process
what is TCB?
a data struct inside the kernel that holds thread specific info
what does p_thread_join(thread_id) do?
it makes the main thread wait until the specified thread exits
what is a critical section?
what is progress? if no other thread is accessing a critical section, a thread will
A piece of code that access a shared resource
How do we avoid multiple threads accessing a shared resource at the same time?
ensure mutual exclusion, progress, and bounded wait
what is mutual exclusion?
condition that only one thread can access a critical section at a time
what is progress?
if no other thread is accessing a critical section, a thread will
what is bounded wait?
once a thread starts trying to enter a critical section, there is a count on the number of other threads that can enter before it does
what is race condition?
when results depend on the timing
what is a mutex?
a synchronization primitive that acts as a lock for a thread in a critical section
how would you make a mutex?
pthread_mutex name;
what is the purpose of pthread_mutex_create(&name)?
it makes a pointer to the mutex object
what is course grained locking:
one big lock used anytime when a critical section is accessed
what is fine grained locking:
different locks used for different resources
what advantage does fine grained locking give:
higher concurrency
what disadvantage does FGL give:
higher risk of deadlock
what is spinning:
when a thread is wasting time constantly checking a condition
what is a condition variable:
an explicit queue that threads can put themselves on when a condition isnt as desired
how do you declare a condition variable:
pthread_cond_t name;
what does pthread_cond_wait(&c,&m) do?
puts a thread in the condition variable c and releases the mutex m atomically
what does pthread_cond_signal(&c) do?
it wakes one thread waiting in the queue
why must you always hold the lock while signaling?
to prevent a race condition where it signals before a thread is put in queue
what is a monitor?
a structure that encapsulates both condition variable and mutex