altro Flashcards
1
Q
What are the benefits and drawbacks of having a process that spawns threads, instead of spawning other processes?
A
Benefits:
- Performance: In a single-threaded process, whenever a blocking system call is executed, the entire process is blocked. With multithreading, other threads can continue executing. For instance, in an application like a spreadsheet program, one thread can handle user interaction while another updates the spreadsheet, leading to better responsiveness.
- Parallelism: Multithreading can exploit parallelism when executed on a multiprocessor or multicore system. Each thread can be assigned to a different CPU or core, allowing for simultaneous execution of threads. This is especially beneficial with the increasing availability of multiprocessor and multicore computers.
- Simplicity in Server Code: Multithreading can simplify server code and make it easier to develop servers that exploit parallelism for high performance, even on uniprocessor systems.
Drawbacks: - Complexity: Threads are not automatically protected against each other the way processes are. This means that developers are responsible for managing concurrent access to shared data, making thread programming notoriously difficult.
- Security and Stability: Processes are isolated from each other by the operating system, providing a level of security and stability. Threads, being part of the same process, share the same memory space. This means that a fault in one thread (like accessing invalid memory) can affect other threads, potentially crashing the entire process.
- Cost of Operations: In certain threading models, every thread operation (creation, deletion, synchronization, etc.) might require intervention by the kernel, making these operations potentially expensive in terms of performance.
2
Q
Would it make sense to limit the number of threads in a server process?
A