• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/71

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

71 Cards in this Set

  • Front
  • Back

Define Cooperating Process (or Thread).

A process or thread that can affect or be affected by other processes executing in the system

What can a 'Cooperating Process' do?

1. Directly share data (threads)


2. Be allowed to share data through files (processes) or messages

Why must access to share data be coordinated?

Data inconsistency

Define Race Condition.

When several processes access and manipulate the same data concurrently and the outcome of the execution depends on the particular order in which the access takes place

Is a 'Race Condition' desirable?

No, we must ensure that coordinating processes
share data without interfering with each other

What happens if two or more processes taking turns reading, modifying, and writing, however they do such out of order?

The data will be inconsistent

Define Critical Section.

A segment of code, in a process, in which it
may be changing variables, tables, writing to
files, and other share dated

How can data inconsistentcy be avoided?

By carefully controlling which process enters
their critical section

How do you control which process enters a 'Critcal Section'?

Each process must request permission to enter its critical section, and no two process are allowed to execute in their critical section at the same time

Define Bounded Waiting in terms of the 'critical section'?

A critical section will usually terminate in fixed
time, and a thread, task or process will have to
wait a fixed time to enter it

When does a process request permission to enter a 'critical section'?

At the entry section

What should a process do once it was completed its 'critical section'?

Release control at the exit section.

List the requirements of a 'Critical Section'.

1. Mutual exclusion


2. Progress


3. Bounded waiting

Define ' Mutual Exclusion' in terms of a 'Critical Section'.

If one process is in its critical
section, then no other processes are in theirs

Define 'Progress' in terms of a 'Critical Section'.

If no process is in its critical section, only processes that aren't in their remainder section can request its critical section.

Define 'Bounded Waiting' in terms of a 'Critical Section'.

There exist a limit/bound on the number of other processes that may enter their critical section after an additional process has made a request and before that request is granted

What tools does the 'POSIX' package include to coordinate synchronization?

1. Mutex locks
2. Conditional variables
3. Read-write locks

Define POSIX.

'Portable Operating System Interface'


Defines the application programming interface (API), along with command line shellsand utility interfaces


Defin Mutex Lock.

A special variable that can be either
locked or unlocked

What happens when a Mutex is 'locked'?

It has a specific thread that holds or owns it

What happens when a Mutex is 'unlocked or free'?

It has no thread currently holding it

What are in the queue of a 'Mutex'?

Threads that are waiting to own it

How is the order of in which threads own the 'Mutex' determined?

The default thread scheduling policy, Often this is FCFS

Why do programs use 'Mutex Locks'

To preserve critical sections and to obtain exclusive access to resources

How long are 'Mutex Locks' meant to be used for?

Small periods of time

What is the ideal use of 'Mutex Locks'?

Making changes to data structures to help protect against inconsistent data

What should you use to synchronize on events of indefinite durations?


Ex) Waiting for input

A conditional Variable

What is the data type of a 'Mutex Lock'?

pthread_mutex_t mLock;

What must be done inorder to create and initialize the 'Mutex Lock'?

A user must create and initialize the mutex lock before using it

What are the 2 option of initializing a 'Mutex Lock'?

1. Static allocation
2. Dynamic allocation

How would you statically allocate a 'Mutex Lock'?

pthread_mutex_t mLock = PTHREAD_MUTEX_INITIALIZER;

How would you dynamically allocate a 'Mutex Lock'?

1. pthread_mutex_t mLock;


2. pthread_mutex_init(&mLock, NULL);

Describe the difference of statically and dynamically allocating a 'Mutex Lock'?

Dynamic allocation allows user to set the specific
attributes of mutex, while static is more efficient

How would you destroy a 'Mutex Lock'?

Using the destroy function


pthread_mutex_destroy(&mLock);

How would you lock a 'Mutex Lock'?

pthread_mutex_lock(&mLock);

How would you unlock a 'Mutex Lock'?

pthread_mutex_unlock(&mLock);

How would you try lock a 'Mutex Lock'?

pthread_mutex_trylock(&mLock);

Describe unlocking and trylocking a 'Mutex Lock'.

Unlocking and trylock return immediately or nonblocking.

Describe locking a 'Mutex Lock'.

Locking is a blocking function, cause any threads
in the mutex queue to be waiting

When are 'Mutex Locks' useful?

Locking a shared resource, modifying it, and
releasing it quickly

Give an example of a poor situation of using a 'Mutex Lock'.

x==y


because the time duration is undefined

How would you create a conditional variable?

pthread_con_t condV;


As with mutex locks, you must initialize conditional variables before using them

What are the 2 options for intializing a conditional variable?

1. Static allocation
2. Dynamic allocation

How would you statically allocate a conditional variable?

pthread_cond_t condV = PTHREAD_COND_INITIALIZER;

How would you dynamically allocate a conditional variable?

1. pthread_cond_t condV;
2. pthread_cond_init(&condV, NULL);

How would you destroy a conditional variable?

pthread_cond_destroy(&condV);

Can a conditional variable be reinitialized once it has been destroyed?

Yes, it can be reinitialized with pthread_cond_init

What must be done first in order to use a conditional varible?

A thread must acquire ownership of the mutex lock first

After a thread has acquire ownership of a 'Mutex Lock', what is done next?

The thread will then call the pthread_cond_wait() function

What will happen when pthread_cond_wait() is called?

The wait operation will cause the thread to release the mutex, and place the thread into the
conditional variable's queue

How is calling pthread_cond_wait() considered efficient?

This allows the thread to be “non-busy” waiting

What happens when a thread returns successfully from pthread_cond_wait?

It has acquired the mutex and can retest the predicate without explicitly reacquiring the mutex lock

From the threads point of view, what happens when a thread returns successfully from pthread_cond_wait?

It “believes” that it has maintained uninterrupted ownership of the mutex. It never realizes
that is has been blocked or waiting

What happens when more than one thread is
waiting on the same condition, and one of the
threads modifies a value that is related to that
conditional?

The thread needs to alert then other threads of
a possible change in the conditional

How does a thread alert another thread of a possible change in the conditional?

Signals

What are the 2 options for alerting other threads of changes?

1. pthread_cond_signal
2. pthread_cond_broadcast

What does pthread_cond_signal do?

Unblock at least one of the threads currently in the conditional variable's queue

What will pthread_cond_broadcast do?

Unblock all of the the threads currently in the conditional variable's queue

What is one type of access that should be granted exclusively?

Writing

What is one type of access that should be shared?

Reading

What are 2 common methods of reader-writer synchronization?

1. Reader synchronization


2. Writer synchronization

What does 'Reader Synchronization' do?

Give readers preference, and granting access to readers as long as a writer is currently writing

What does 'Writer Synchronization' do?

Give writers preference, delaying all readers until all waiting or active writers complete

What does POSIX do?

Allows the programmer to determine how/when a reader acquires a lock if writers are waiting

What is the the data type for 'Read-Write Locks'?

pthread_rwlock_t RWLOCK;

What is done before a 'Read-Write Lock' (RW Lock) can be used?

Initialized using the pthread_rwlock_init()
function

How would you destroy a 'Read-Write Lock' (RW Lock)

To destroy a RW lock use the pthread_rwlock_destroy function

How would you acquire a read-write lock for reading?

Use the pthread_rwlock_rdlock () function

How would you acquire a read-write lock for writing?

Use the pthread_rwlock_wrlock() function

What do the pthread_rwlock_rdlock () function and the pthread_rwlock_wrlock() function have in common?

Both functions will block until lock is available

How would you unlock a Read-Write Lock?

Use pthread_rwlock_unlock() function