Вы находитесь на странице: 1из 3

Name: Daniel Saigua Labre Date: 27/10/19

Chapter 4: Threads

4.1 How many threads does a traditional, heavyweight process have?

A traditional (orheavyweight) process has a single thread of control.

4.2 Provide at least three benefits of multithreaded programming.

1. Economy
2. Scalability
3. Responsiveness
4. Resource sharing

4.3 True or False? Concurrency is only possible with parallelism.

False, because Parallelism is a particular case of Concurrence.

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.6 What are the two general types of parallelism?

1. Task parallelism: Task parallelism focuses on distributing tasks—concurrently


performed by processes or threads—across different processors.
2. Data parallelism: Distribution of data sets across the multiple computation programs.

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.

4.10 What are the three main thread libraries in use?

Three main thread libraries are in use today:

1. POSIX Pthreads
2. Win32
3. Java.

4.11 True or False? PThreads is typically only implemented on UNIX-like systems.

True. UNIX and Linux systems often use Pthreads.

4.12 True or False? PThreads is only a specification, not an implementation.

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.

4.13 What is the PThread API for creating a thread?

Is created with the pthread create() function call.

4.14 What is the Windows API for creating a thread?

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.

4.16 Provide at least two techniques for supporting implicit threading.

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?

Asynchronous cancellation: One thread immediately terminates the target thread.


Name: Daniel Saigua Labre Date: 27/10/19

Deferred cancellation: The target thread periodically checks whether it should terminate,
allowing it an opportunity to terminate itself in an orderly fashion.

4.20 What is the PThreads API for thread cancellation?

The pthread_cancel() function sends a cancellation request to the thread thread.

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.

4.22 What term does Linux use to refer to a process or a thread?

Linux generally uses the term task rather than process or thread.

Вам также может понравиться