# data[].attributes.body
Salam

Chapter 4 : Thread

1.What is thread?

•A thread is a path of execution within a process. A process can contain multiple threads.. It works simultaneously with many other threads and execute together.

2.Type of thread can be processed

•Single threaded

•Multithreaded

3.How much time is required to create a new thread in an existing process ?

•Less than the time requires to create a new process.

4.List down what is a valid state of a thread

•Running

•Ready

•Blocked

5.Why thread synchronization is required

a) all threads of a process share the same address space

b) all threads of a process share the same global variables

c) all threads of a process can share the same files

6.The jacketing technique is used to

•convert a blocking system call into non blocking system call

7.When the event for which a thread is blocked occurs

•when thread move to the ready queue

8.Give the other name of thread

•Light Weight Process(LWP)

9.A heavy weight process can be...

•A single thread of execution.

10.The kernel is _______ of user threads.

•unaware of

# data[].attributes.body
1. Give 4 benefits of Multithread Server Architecture.

a. Responsiveness

b. Resource sharing

c. Economy

d. Scalability

2. State 5 challenge of Multicore Programming.

a. Dividing activities

b. Balance

c. Data splitting

d. Data dependency

e. Testing and debugging

3. Define Parallelism.

Parallelism implies a system can

perform more than one task

simultaneously.

4. Give 2 types of Parallelism.

a. Data parallelism – distributes subsets

of the same data across multiple

cores, same operation on each

b. Task parallelism – distributing

threads across cores, each thread

performing unique operation

5. Describe Amdahl’s Law.

Identifies performance gains from

adding additional cores to an

application that has both serial and

parallel components.

6. What is User threads?

User threads - management done by

user-level threads library.

7. Give 3 primary thread libraries.

a. POSIX Pthreads

b. Windows threads

c. Java threads

8. What is Kernel threads and give 5 example.

Kernel threads - Supported by the

Kernel

Examples – virtually all general purpose

operating systems, including:

a. Windows

b. Linux

c. MacOSX

d. iOS

e. Android

9. Give 3 Multithreading Models.

a. Many-to-One

b. One-to-One

c. Many-to-Many

10. What thread library do?

Thread library provides programmer

with API for creating and managing

threads

# data[].attributes.body
1. What is thread?
A thread is a path of execution within a process. A process can contain multiple threads.. It works simultaneously with many other threads and execute together.

2. What is multithreading?
A thread is also known as lightweight process. The idea is to achieve parallelism by dividing a process into multiple threads. For example, in a browser, multiple tabs can be different threads. MS Word uses multiple threads: one thread to format the text, another thread to process inputs, etc.

3. What do we need to support thread?

Threads data structure

Identify threads, keep track of resource usage..

Mechanisms to create and manage threads

Mechanisms to safely coordinate among threads running concurrently in the same address space

4. What is the advantages of thread over process?

Responsiveness: If the process is divided into multiple threads, if one thread completes its execution, then its output can be immediately returned.

Faster context switch: Context switch time between threads is lower compared to process context switch. Process context switching requires more overhead from the CPU.

Effective utilization of multiprocessor system: If we have multiple threads in a single process, then we can schedule multiple threads on multiple processor. This will make process execution faster.

Resource sharing: Resources like code, data, and files can be shared among all threads within a process.

5. List two types of thread.
- User Level Thread
- Kernel Level Thread

6. Differentiate between user level and kernel level thread.
User level thread

Implemented by users.

OS doesn’t recognized user level threads.

Implementation of User threads is easy.

Kernel level thread

Implemented by OS.

Kernel threads are recognized by OS.

Implementation of Kernel thread is complicated.

7. Differentiate between one-to-one model, many-to-one model and many-to-many model.
One-to-one model

OS sees threads

Must go to OS for all operations

Many-to-one model

Doesn't depend on OS limits and policies

OS may block entire process if one user-level thread blocks on I/O

Many-to-many model

Can have bound or unbound threads

Requires coordination between user and kernel level thread managers

8. What is thread library?
Thread libraries provide programmers with an API for creating and managing threads. Thread libraries may be implemented either in user space or in kernel space.

9.What is function of concurrency?
Supports more than one more task making progress.

10. Give 2 threads cancellation scenarios.
- Asynchronous cancellation
- Deferred cancellation

# data[].attributes.body
1) What is the difference between the user threads and kernel threads?

-User threads management is done by user-level threads library while Kernel threads is supported by the kernel

2) Explain 4 benefits of multithreaded programming.

-Responsiveness. Multithreading an interactive application may allow
a program to continue running even if part of it is blocked or is
performing a lengthy operation, thereby increasing responsiveness to
the user.
-Resource sharing. Processes commonly share resources through techniques
such as shared memory and message passing.
-Economy. Allocating memory and resources for process creation is costly.
-Scalability. The benefits of multithreading can be even greater in a
multiprocessor architecture, where threads may be running in parallel
on different processing cores.

3) State 3 multithreading models

-Many-to-one Model
-One-to-one Model
-Many-to-many model

4) What is thread libraries and describe two primary ways of implementing a thread library?

-A thread library provides the programmer with an API for creating and
managing threads. There are two primary ways of 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.

5) What is function of concurrency?

-Supports more than one more task making progress.

6) Give three primary thread libraries

-POSIXPthreads

-Windows threads

-Java threads

7) Give 2 threads cancelation scenarios

-Asynchronous cancellation
-Deferred cancellation

8) How does schedular activation works?

-The kernel
provides an application with a set of virtual processors (LWPs), and the
application can schedule user threads onto an available virtual processor.

9) Give the general components of a thread for windows

-A thread ID uniquely identifying the thread
-A register set representing the status of the processor
-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
-A private storage area used by various run-time libraries and dynamic link
libraries (DLLs)

10) Show multithreaded server architecture

# data[].attributes.headline
SITI HAZIMAH BINTI MOHD IDRIS (2017668794)

# data[].attributes.subject
SITI HAZIMAH BINTI MOHD IDRIS (2017668794)

# data[].attributes.headline
SITI HAZIMAH BINTI MOHD IDRIS (2017668794

# data[].attributes.subject
SITI HAZIMAH BINTI MOHD IDRIS (2017668794

# data[].attributes.headline
Siti Nur 'Aishah Binti Mohd Rafi (2017669194)

# data[].attributes.subject
Siti Nur 'Aishah Binti Mohd Rafi (2017669194)

# data[].attributes.body
2017668882

# data[].attributes.headline
Siti nur fatihah binti nor azman (2017668902)

# data[].attributes.subject
Siti nur fatihah binti nor azman (2017668902)

# data[].attributes.headline
Siti nur fatihah binti nor azman (2017668902

# data[].attributes.subject
Siti nur fatihah binti nor azman (2017668902

# data[].attributes.headline
NUR AYLA FARIHAH BINTI ROSLAN (2017668942)

# data[].attributes.subject
NUR AYLA FARIHAH BINTI ROSLAN (2017668942)

# data[].attributes.headline
Nur Amirah Dayana Binti Jaafar (2017668874)

# data[].attributes.subject
Nur Amirah Dayana Binti Jaafar (2017668874)

# data[].attributes.headline
NOR AFIDAH BINTI MOHD HADZIR  ( 2017668792 )

# data[].attributes.subject
NOR AFIDAH BINTI MOHD HADZIR  ( 2017668792 )

# data[].attributes.body
2017668924

1) How to implement multiple tasks using seperated threads?
-Update display
-Fetch data
-Spell checking
Answer a network request

2) What is parallelism?
Parallelism implies a system that can perform more than one task simultaneously.

3)How many types of parallelism and describe them?
-data parallelism : distributes subsets of the same data across multiple cores
-task parallelism : distribute threads across cores

4)What is 3 primary thread libraries?
-POSIX Pthreads
-Windows threads
Java threads

5)What is multithreading models?
- Many-to-One
- One-to-One
- Many-to-Many

6)One examples for each multithreading.
-Many-to-one : Solaris Green Threads
-One-to-One : Linux
-Many-to-Many : Windows with ThreadFiber package

7)Two primary ways to implement thread libraries?
-Library entirely in user space
-Kernel-level library supported by the OS

8)Describe two types of dispatch queues
-Serial : Blocks removed in FIFO order, queue is per process called main queue
-Concurrent : Removed FIFO in order but several may be removed at the same time

9) Give three threading issues
-Signal handling
-thread cancellation of target thread
-schedular activations

10)Describe two general approaches of thread cancellation
-Asynchronous cancellation: Terminates the target thread immediately
-Deferred cancellation: Allows target thread to periodically check if it should be cancelled.

# data[].attributes.headline
Please submit your Questions and Answer for Topic 4 here

# data[].attributes.subject
Please submit your Questions and Answer for Topic 4 here

# data[].attributes.body
Click on the '+' symbol to create new posting.
Make sure to write your name for each submission