Ch5 Concurrent Computing Flashcards
Ch5 Concurrent Computing
What is concurrent computing ?
Concurrent computing is a form of computing where multiple computations are executed during overlapping time periods (concurrently) instead of sequentially. It involves multiple processes or threads working together to accomplish tasks faster.
What are the three forms of concurrency?
- Distributed Systems: Multiple machines working together over a network.
- Multi-Process Systems: Multiple processes running on the same machine.
- Multi-Threaded Systems: Multiple threads within a single process sharing the same memory space.
What is a distributed system?
A distributed system is a program that executes over multiple physical machines, often in different locations, communicating over a network (e.g., intranet or internet). It is used for speed, necessity, and convenience.
What is a multi-process system?
A multi-process system involves multiple processes (executables) running simultaneously on the same machine, each with its own control flow and virtual memory. Processes communicate via Inter-Process Communication (IPC).
What is a multi-threaded system?
A multi-threaded system is a single process with multiple threads sharing the same memory and resources. Threads take turns using the CPU, and synchronization is needed to avoid race conditions and deadlocks.
What are the main issues in concurrent systems?
- Shared Resources: Multiple processes/threads accessing the same resource (e.g., files, variables).
- Deadlocks: Multiple processes/threads are blocked, waiting for each other to release resources.
- Race Conditions: The correctness of the program depends on the order of execution, which can lead to unpredictable results.
What is a mutex?
A mutex (mutual exclusion object) is a program object that allows multiple threads to take turns sharing a resource. Only the thread that locks the mutex can unlock it.
What is a semaphore?
A semaphore is a variable used to control access to a shared resource by multiple processes or threads. It is a generalization of a mutex and can signal other threads when a resource is available.
What is process management?
Process management involves allocating resources to processes, enabling them to share and exchange information, protecting resources, and enabling synchronization among processes.
What is the difference between foreground and background processes?
Foreground: The process runs in the terminal, and you cannot use the shell until it completes.
Background: The process runs independently, allowing you to continue using the shell (use & to run in the background).
What is the purpose of the fork() function in C?
The fork() function creates a new process (child) that is a copy of the current process (parent). The child process starts execution from the point where fork() was called.
What is the purpose of the exec() family of functions?
The exec() functions replace the current process’s code with a new program. The new program runs in the same process with the same PID.
What is the purpose of the wait() function?
The wait() function pauses the execution of a parent process until one of its child processes terminates. It returns the PID of the terminated child.
What is the purpose of the system() function?
The system() function allows a program to execute a shell command as if it were typed in the terminal. The process blocks until the command completes.
What is Inter-Process Communication (IPC)?
IPC is the sending and receiving of information between processes. It can occur on the same machine or between different machines over a network.
What is a signal in IPC?
A signal is a value (integer) sent from one process to another to inform it of an event (e.g., termination, error). It is a rudimentary form of communication.
What is a socket in IPC?
A socket is an endpoint for sending or receiving data between processes. It can be used for communication on the same machine or over a network.
What are the three types of sockets?
- Stream Sockets: Connection-based (e.g., TCP).
- Datagram Sockets: Connectionless (e.g., UDP).
- Raw Sockets: Bypass the transport layer.
What is the client/server model?
In the client/server model, one process (server) receives requests from multiple clients and performs tasks accordingly. It is commonly used in network communication.
What is the difference between TCP and UDP?
TCP: Connection-based, reliable, ensures data is delivered in order.
UDP: Connectionless, faster, but data may be lost, corrupted, or arrive out of order.
What is a thread?
A thread is a sequence of programmed instructions that can be managed independently by the operating system. Threads within the same process share memory and resources.
What is the purpose of the pthread_create() function?
The pthread_create() function creates a new thread within a process. It takes a function pointer as an argument, which is the starting point for the thread.
What is a race condition?
A race condition occurs when the correctness of a program depends on the order of execution of threads or processes. It can lead to unpredictable results.
How can you prevent race conditions?
Race conditions can be prevented using synchronization mechanisms like mutexes and semaphores to ensure that only one thread accesses shared resources at a time.
What is the purpose of the volatile keyword in C?
The volatile keyword indicates that a variable’s value may change unexpectedly (e.g., by another thread). It prevents the compiler from optimizing access to the variable.
What is the purpose of the sem_wait() and sem_post() functions?
sem_wait(): Decrements the semaphore, blocking if the semaphore is 0.
sem_post(): Increments the semaphore, allowing other threads to access the resource.
What is the difference between pass-by-value and pass-by-reference in C?
Pass-by-value: A copy of the value is passed to the function. Changes do not affect the original variable.
Pass-by-reference: The address of the variable is passed, allowing the function to modify the original variable.
What is the purpose of the select() function in socket programming?
The select() function monitors multiple file descriptors (e.g., sockets) to see if they are ready for reading, writing, or have an exceptional condition. It is used in UDP servers to handle multiple clients.
What is the purpose of the recvfrom() and sendto() functions?
recvfrom(): Receives data from a UDP socket.
sendto(): Sends data to a UDP socket.
What is the purpose of the pthread_join() function?
The pthread_join() function blocks the calling thread until the specified thread terminates. It allows the main thread to wait for other threads to complete.