Exam 2

¡Supera tus tareas y exámenes ahora con Quizwiz!

When a thread is waiting to enter a critical section using a std::lock_guard, its CPU usage will be

0%

What are the four conditions that must be met to establish an effective critical section in a multi-threaded program?

1.) No two threads in the same critical section simultaneously 2.) No assumptions about speed or number of cores/CPUs 3.) No thread outside the critical section may block a thread inside the critical section 4.) No thread should wait forever to enter the critical section

List 2 key differences between named and anonymous pipes

1.) Unlike a traditional pipe that is "unnamed" (as it exists anonymously and persists only for as long as the interacting process is running) named pipes exist beyond the lifetime of processes; meaning, a named pipe is system-persistent and exists beyond the life of the process. 2.) An unnamed pipe is only used for communication between a child and it's parent process, while a named pipe can be used for communication between two unnamed processes as well. Processes of different ancestry can share data through a named pipe.

A multithreaded program has 4 threads that run in parallel on 4 core machine. Each thread runs for 2 minutes. The total run time of the program would be

2 minutes

Given 8 independent, shared resources, the optimal number of mutexes to maximize concurrent, thread-safe access to the 8 resources is

8

In OS terminology, what is a pipe?

A UNIX pipe is a kernel buffer with two file descriptors, one for writing (to put data into the pipe) and one for reading (to pull data out of the pipe).

execlp() and execvp()

A lengthier way to run commands in linux, can take 3 arguments

What is a mutex?

A mutex controls which thread has access to a specific variable. If the mutex is in the possession of a thread then the other threads can't access that data value until the thread gives up control of the mutex.

How does the OS manage pipes?

A pipe is a connection between two processes, such that the standard output from one process becomes the standard input of the other process. In UNIX Operating System, Pipes are useful for communication between related processes (inter-process communication). A pipe can be implemented as a 10k buffer in main memory with 2 pointers, one for the FROM process and one for TO process.

What is the difference between a semaphore and a mutex?

A semaphore is a shared-variable signaling mechanism that counts the number of wakeups. It also restricts the number of simultaneous users of a shared resource, but still allows some to get in. When a mutex object is held by a particular thread, that thread locks downs resources for exclusive use. No one else can use the resources of that thread.

What is a semaphore?

A semaphore tells a process how many wakeups there are in a program. It essentially defines how many tasks are running and whether another task can start running. It limits number of consumers on specific resources.

Parallelism

A system can perform more than one task simultaneously

What is the difference between unordered_map and vector?

A vector uses a small amount of memory but is slow. An unordered_map uses more memory and is faster.

Multithreading

Allows different parts of a single program to run concurrently. Running concurrently = multiple points of execution at given time.

Named pipe

Can last as long as the system is up, beyond the life of the process unlike a traditional pipe

fork()

Creates a child process

Data parallelism

Distributes subsets of the same data across multiple cores, same operation on each. (Data is divided among threads, which all do the same task.)

Task parallelism

Distributing threads across cores, each thread performing unique operation. (Tasks are divided among threads, which all use the same data.)

dup2()

Duplicates a file descriptor and closes the old one

recv()

Equivalent to read(). Receives messages from a socket.

send()

Equivalent to write(), but send() never takes flags. Cannot be used in UDP. Sends messages from a socket.

T/F: Concurrency is only possible with parallelism.

False

T/F: Concurrency implies parallelism

False. But parallelism almost always implies concurrency.

join()

Joins two child processes together

ps

Lists all current processes

Determine if the following problems exhibit task or data parallelism: Merge Sort Finding Min/Max Multithreaded HTTP Web Server

Merge Sort: Data parallelism Finding Min/Max: Task parallelism Multithreaded HTTP: Task parallelism

Multiprogramming

Multiprogramming is when a program or operating system can manage more than 1 user at the same time or manage multiple requests at the same time. Essentially, it's the ability for a program to multitask.

If process pi is executing in its critical-section, then no other processes can be executing in their critical-sections. Technique is called

Mutual Exclusion

The bare minimum number of cores and CPUs that are required to run a multithreaded program is

One CPU with 1 core

How does join() work? Use P and C to refer to threads.

P executes join() to join with C, which is still running. P is suspended until C terminates. Once C terminates, P resumes. P executes join() and C has already terminated, so P continues as if nothing has been executed (i.e., join has no effect).

PID

Process ID

read()

Read from a file descriptor

5 benefits of a multithreaded server architecture

Responsiveness, resource sharing, economy, and scalability

Anonymous pipe

Simplex (one direction only) FIFO communication channel that may be used for one way Inter-Process Communication (IPC)

Concurrency

Supports more than one task making progress at a time

Pipe command

Takes the output of one command and directs it into the input of another

What information is used by a process running on one host to identify a process running on another host?

The IP address of the destination host and the port number of the destination socket.

Given a C++ source file named exam2.cpp, the executable generated by compiling it must be named

The executable can have any name

Calling the join() method on a running thread causes

The join call to block (and wait for the thread to finish)

For a communication session between a pair of processes, which process is the client and which is the server?

The process that initiates communication is the client, and the process that waits to be contacted is the server.

If a thread has already finished running, then calling the join() method on the thread causes

The thread to terminate normally without any issues

UDP servers need only one socket, whereas TCP servers need two sockets, why? If the TCP server is to support n simultaneous connections, each from a different client host, how many sockets would the TCP server need?

This is because UDP is a connectionless protocol and TCP is a connection-oriented protocol. TCP has a welcoming socket (to accept incoming connections), and then for each connection it receives, it creates a new socket. For n simultaneous connections, a TCP server would need N + 1 sockets.

TCP

Transmission Control Protocol - provides reliable, ordered, and error-checked delivery of a stream of packets on the internet. TCP is tightly linked with IP and usually seen as TCP/IP in writing. Maintained until the application programs at each end have finished exchanging messages.

T/F: A device which works with one Linux distribution may not necessarily work with others.

True

T/F: A non-preemptive kernel is essentially free from race conditions.

True

T/F: Amdahl's Law addresses the disproportionate effect of the serial portion of a program.

True

T/F: If a multi-threaded program runs correctly in all cases on a single time-sliced processor, then it will run correctly if each thread is run on a separate processor of a shared-memory multiprocessor.

True

T/F: Most operating systems allow a process to have multiple threads.

True

T/F: PThreads is only a specification, not an implementation.

True

T/F: PThreads is typically only implemented on UNIX-like systems.

True

T/F: The semantics of the fork() system call can vary on multithreaded systems.

True

T/F: The view most users see of the operating system is defined by application and system programs rather than system calls.

True

Suppose you wanted to do a transaction from a remote client to a server as fast as possible. Would you use UDP or TCP? Why?

UDP, because UDP prioritizes speed over efficiency. So while data loss is possible, the transaction can be completed in one round-trip time since there's no need to establish a connection, it just starts sending data.

recvfrom()

Used to receive messages from a socket, must take an argument for the socket address.

sendto()

Used to transmit messages to another socket

UDP

User Datagram Protocol. Used instead of TCP when guaranteed delivery of each packet is not necessary. UDP uses a best-effort delivery mechanism.

wait(NULL)

Waits for child process to finish executing before continuing

wait(pid)

Waits for specific pid to finish execution before continuing

write()

Write to a file descriptor

In order to use 2 resources protected by 2 mutexes m1 and m2, the preferred order of locking the mutex would be

std::lock(m1, m2);


Conjuntos de estudio relacionados

About Behaviorism Ch 1 (Causes of Bx)

View Set