Академический Документы
Профессиональный Документы
Культура Документы
Chapter 4: Threads
1. Economy
2. Scalability
3. Responsiveness
4. Resource sharing
4.4 True or False? Amdahl’s Law addresses the disproportionate effect of the serial portion of
a program.
True, We can also say that this law is used to find out the maximum improvement of an
information system when only a part of it is improved.
4.5 List at least three challenges when designing programming for multicore systems.
1. Testing and debugging: When a program is running in parallel on multiple cores, there
are many different execution paths. Testing and debugging such concurrent programs
is inherently more difficult tan testing and debugging single-threaded applications.
2. Data dependency: The data accessed by the tasks must be examined for dependencies
between two or more tasks.
3. Balance: While identifying tasks that can run in parallel, programmers must also ensure
that the tasks perform equal work of equal value.
4.7 List the three common ways of mapping user threads to kernel threads.
1. Many to one model: The many-to-one model maps many user-level threads to one
kernel thread.
2. One to one model: The one-to-one model maps each user thread to a kernel thread
3. Many to many model: The many-to-many model multiplexes many user-level threads
to a smaller or equal number of kernel threads.
4.8 True or False? Only Linux and Windows implement the one-to-one model.
True, Linux, along with the family of Windows operating systems, implement the one-to-one
model.
Name: Daniel Saigua Labre Date: 27/10/19
4.9 What are the two approaches for implementing a thread library?
The first approach is to provide a library entirely in user space with no kernel support. The
second approach is to implement a kernel-level library supported directly by the operating
system.
1. POSIX Pthreads
2. Win32
3. Java.
True. Pthreads refers to the POSIX standard (IEEE 1003.1c) defining an API for thread creation
and synchronization. This is a specification for thread behavior, not an implementation.
Threads are created in the Win32 API using the CreateThread() function.
4.15 What Java method is used for allocating and initializing a new thread in the JVM?
Calling the start() method for the new object: It allocates memory and initializes a new thread
in the JVM.
1. Thread pools: Is to create a number of threads at process startup and place them into
a pool, where they sit and wait for work.
2. openMP: The task is divided into K threads (fork) with less weight, then "collect" their
results at the end and join them into a single result (join).
4.17 True or False? Grand Central Dispatch only works for Apple’s Mac OS X and iOS
operating systems.
True.
4.18 True or False? The semantics of the fork() system call can vary on multithreaded
systems.
True. The semantics of the fork() and exec() system calls change in a multithreaded program.
4.19 What are the two scenarios for canceling a target thread?
Deferred cancellation: The target thread periodically checks whether it should terminate,
allowing it an opportunity to terminate itself in an orderly fashion.
4.21 True or False? Windows threads provide both user and kernel stacks.
True. A user stack, employed when the thread is running in user mode, and a kernel stack,
employed when the thread is running in kernel mode.
Linux generally uses the term task rather than process or thread.