CST 334 - Concurrency

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Process Memory

*Heap*Text section* made up of *compiled program code*, read from non-volatile storage when the program is launched. *Data section* made up of *global and static variables*, allocated and initialized prior to executing the main. *Heap* used in *Dynamic memory allocation*, and is managed via calls to *new, delete, malloc, free*, etc. *Stack* used for *local variables*. Space on the stack is reserved for local variables when they are declared.

How many condition variables are used in the Anderson/Dahlin method?

0 or more

Semaphore

are integer variables that are used to solve the critical section problems by using two atomic operations, wait and signal that are used for process synchronization.

Serialization

process of translating data structures or object state into a format that can be stored( ex, in a file or a memory buffer) or transmitted (ex. across a network connection) and reconstructed later.

What is the blocking operation in the pthreads API?

pthread_cond_wait

Blocking operation

puts the calling process on wait until the event (on which the call is blocked) occurs after which the process is woken up and is ready for execution.

Process Synchronization

sharing system resources by processes in such a way that, concurrent access to shared data is handled thereby minimizing the chance of inconsistent data. Maintaining data consistency demands mechanisms to ensure synchronized execution of cooperating processes.

Synchronization Instructions

tell one thread to wait until some action is performed by another thread before the former continues its execution.

Asynchronous

the API always returns immediately, having started a "background" effort to fulfill your request, so there must be some related way to obtain the result.

sem.signal

the signal operation increments the value of its argument S

sem.wait

the wait operation decrements the value of its argument S, if it is positive. If S is negative or zero, then no operation is performed.

Properties of lock

1. A lock can be in one of two states: busy or free. 2. A lock is initially in the free state. 3. The lock operation waits until the lock is free, and automatically makes the lock busy. 4. The unlock operation makes the lock free. 5. 'Lock' is sometimes called 'acquire' 6. 'Unlock' is sometimes called 'free'

Using locks for mutual exclusion

1. A lock is an object that can be "held" by only one thread at a time. 2. A lock can be acquired by a thread. 3. A lock can be released by a thread.

Thread

1. Are a sequence of execution code which can be executed independently of one another. a. it is the smallest unit of tasks that can be executed by an OS 2. A program can be single threaded or multi-threaded.

Threads

1. Threads are faster to create, destroy, and context switch. 2. Threads within a process share a virtual address space. 3. *Each thread has it own stack and its own registers.*

Shared Memory

1. concurrent modules interact by reading and writing shared objects in memory. 2. two threads can communicate by having a shared memory location that one writes to and the other reads from. 3. But then the value read by the latter depends on whether the read occurred before or after the former wrote to that memory location. 4. Worse still, if the read and write happen at the same time, it's possible for the reader to see a partially updated value because the writer started updating it but did not finish before the reader read the value. 5. In order to avoid this use synchronization.

Condition variable

1. synchronization primitives that enable threads to wait until a particular condition occurs. 2. condition variables are user-mode objects that cannot be shared across processes. 3.used to wait for a particular condition to become true (eg. characters in buffer).

without proper synchronization of bounded buffer:

1. the producers doesn't block when the buffer is full 2. a consumer consumes an empty slot in the buffer 3. a consumer attempts to consume a slot that is only half-filled by a producer. 4. two producers writes into the same slot. 5. two consumers reads the same slot.

Thread-safe data structure

A method or class instance can be used by multiple threads at the same time without any problems occurring.

When a thread calls wait(), the lock it passes must be in which state?

ACQUIRED note: the thread must be holding the lock when it calls wait()

A ______ is a piece of code that accesses a shared resource, such as a shared variable.

CRITICAL SECTION

What do threads use to signal other threads in the pthreads API?

Condition variables

Two processes may share memory if they each have multiple threads?

FALSE

Processes can have zero threads

FALSE note: every process has at least one thread.

All threads of a process run the same code?

FALSE note: Take for example the readers/writers problem. The readers and writers are threads in the same process.

Condition variables can be implemented with locks

FALSE note: the only state of a lock is whether it is busy or free.

The function 'pthread_create' creates a clone of the currently running thread ( like 'fork' of the process API)

False note: one of the parameters of pthread_create specifies the function that should be run by the newly-created thread.

Minimum number of threads in a process?

ONE

When multiple threads are running, and the output depends on the timing of their execution, then the code has a _____.

RACE CONDITION

The wait() call on condition variable requires a parameter for a condition variable and a parameter for a lock.

TRUE

Threads of the same process can share variables?

TRUE

When a lock is initialized, it is in the 'free' state.

TRUE

If your code is designed following the Anderson/Dahlin guideline, then your code will never break is a 'spurious wakeup' occurs.

TRUE note: A spurious wakeup is when a call to wait() returns if a signal has not occurred

In the Anderson/Dahlin style of designing shared objects, each object has one lock

TRUE note: The lock is used to ensure mutually exclusive access to shared variables

Race condition

When multiple threads are running, and the output depends on the timing of their execution.

Critical section

a code segment that accesses shared variables and has to be executed as an atomic action. This means that in a group of cooperating processes, at a given point of time, only one process must be executing its critical section. If any other process also wants to execute its critical section, it must wait until the first one finishes.

Process

a program in execution. || an instance of a running program. a program can have multiple processes. a process usually starts with a single thread (a primary thread), but later down the line of execution it can create multiple threads.

Mutual exclusion

a program object that prevents simultaneous access to a shared resource *out of a group of cooperating process, only one process can be in its critical section at a given point of time.*

Execution path

a sequence of instructions, that is managed separately by the operating system scheduler as a unit.

Deadlock

a set of blocked processes each holding a resource and waiting to acquire a resource held by another process. occurs when a process or thread enters a waiting state because a requested system resource is held by another waiting process, which in turn is waiting for another resource held by another waiting process.

Create an alias called clr for the clear command.

alias clr="clear"

Threads and processes

both have state.

Shared data

by using a designated area of shared memory, the data can be made directly accessible to both processes without having to use the system services. check semaphore value, write the data, and then reset the semaphore to signal to the server that data is waiting. In turn, the server process writes data back to the shared memory area using the semaphore to indicate that data is ready to be read.

process

contains one or more threads

Concurrency

executing multiple tasks at the same time but not necessarily simultaneously. In a concurrent application, two tasks can start, run, and complete in overlapping time periods i.e Task-2 can start even before Task-1 gets completed.

Create a global bash variable foo and set it equal to the string bar

export foo=bar

Lock

is a blocking operation.

Bounded buffer

lets multiple producers and multiple consumers share a single buffer. Producers write data to the buffer and consumers read data from the buffer. Producers must block if the buffer is full. Consumers must block if the buffer is empty.

Non-blocking

means that if an answer can't be returned rapidly, the API returns immediately with an error and does nothing else. There must be some related way to query whether the API is ready to be called.(that is to simulate a wait in an efficient way).

lock

method of synchronization used to prevent multiple threads from accessing a resource at the same time.

Synchronization primitive

mutex, event, conditional variables, and semaphores are all synchronization primitives. So are shared locks and exclusive locks. you need some synchronization primitives to protect critical section.

At most one thread at a time can be in the critical section - this is ____.

mutual exclusion

Non-determinism

non-predictive. Inability to objectively predict an outcome or result. or for the same input, the compiler may produce different output in different runs.

Atomic operations

operations that finish their tasks as a whole, ie. no other interruption is allowed before its completion.

Which condition variable operations are blocking?

wait

Spurious wakeup

when we wake threads up knowing that they may not be able to proceed. Even after a condition variable appears to have been signaled from a waiting thread's point of view, the condition that was awaited may still be false.

Assign the output of the command date to a variable x.

x=$(date)


Kaugnay na mga set ng pag-aaral

Accounting-Product vs. Period Costs

View Set

Algebra 2 - 2.2, 2.4, 2.7 Problems

View Set

Bio True/ False, Bio Exam 3, Bio Exam 2 Chapter 4, 5, 15, 25, 6, 22

View Set

Ch 11 SB: Pure Competition in the Long Run

View Set

Biol 3840: Chp 13 - Cnidaria & Ctenophora

View Set

Writing Equations in Slope-Intercept Form Practice

View Set