Process Management: Threads

studied byStudied by 1 person
5.0(1)
learn
LearnA personalized and smart learning plan
exam
Practice TestTake a test on your terms and definitions
spaced repetition
Spaced RepetitionScientifically backed study method
heart puzzle
Matching GameHow quick can you match all your cards?
flashcards
FlashcardsStudy terms and definitions
Get a hint
Hint

what are the different ways a CPU can execute its tasks?

1 / 40

flashcard set

Earn XP

Description and Tags

41 Terms

1

what are the different ways a CPU can execute its tasks?

sequential execution

concurrent execution

parallel execution

parallel and concurrent execution

each execution method is a different combination of parallel and concurrent

New cards
2

what are the different combinations of parallel and concurrent that applications can be executed with?

not parallel : not concurrent

parallel : not concurrent

not parallel : concurrent

parallel : concurrent

New cards
3

what combination of parallel and concurrent is SEQUENTIAL?

not parallel : not concurrent

New cards
4

what combination of parallel and concurrent is CONCURRENT?

not parallel : concurrent

New cards
5

what combination of parallel and concurrent is PARALLEL?

parallel : not concurrent

New cards
6

what is sequential execution?

  • Application processes and executes one task or subtask (job, process) at a time

  • Needs to complete its execution for another task to start

  • not efficient, old solution

<ul><li><p>Application processes and executes one task or subtask (job, process) at a time</p></li><li><p>Needs to complete its execution for another task to start</p></li><li><p>not efficient, old solution</p></li></ul>
New cards
7

what is concurrent execution?

  • application processes more than one task at the same time, but no two tasks are executed at same time instant.

  • Multiple tasks or subtasks appear to run in parallel

  • Takes advantage of the CPU time-slicing feature of the operating system → Takes share of time (managed by the operating system)

  • Runs part of a task then go to waiting state. While in the waiting state another task is running and so on → processes are in different states (eg. waiting, running) and can change states

<p></p><p></p><ul><li><p>application processes more than one task at the same time, but no two tasks are executed at same time instant.</p></li><li><p>Multiple tasks or subtasks <strong>appear</strong> to run in parallel</p></li><li><p>Takes advantage of the CPU <mark data-color="red">time-slicing</mark> feature of the operating system → Takes share of time (managed by the operating system)</p></li><li><p>Runs part of a task then go to <mark data-color="yellow">waiting</mark> state. While in the waiting state another task is <mark data-color="yellow">running</mark> and so on → processes are in different states (eg. waiting, running) and can change states</p></li></ul>
New cards
8

what is parallel execution?

  • application processes and executes multiple tasks at the same time executing at the same time

  • Requires two or more CPUs/cores

  • eg. for 1 point in time, many tasks may be running

<ul><li><p>application processes and executes multiple tasks at the same time executing at the same time</p></li><li><p>Requires two or more CPUs/cores</p></li><li><p>eg. for 1 point in time, many tasks may be running</p></li></ul>
New cards
9

what is parallel and concurrent execution?

  • eg. multiple CPUs means parallel tasks can run, but within each CPU the tasks run concurrently

<ul><li><p>eg. multiple CPUs means parallel tasks can run, but within each CPU the tasks run concurrently</p></li></ul>
New cards
10

what is parallelism?

  • one application divided into subtasks that can be mapped to different CPUs, communication between the subtasks occurs

<ul><li><p>one application divided into subtasks that can be mapped to different CPUs, communication between the subtasks occurs</p></li></ul>
New cards
11

what is the difference between parallel execution and paralleism?

  • if the program not developed as parallel then cannot be run in parallelism as parallelism

  • for parallel execution applications don’t need to be specifically developed to suit it. parallel execution works as long as the tasks happening on each CPU are different at a given time

New cards
12

what is the difference between concurrency and parallelism?

  • concurrency | parallelism

  • tasks start/ run/ complete in overlapping time periods vs. tasks run at the same time

  • processes execute independently vs. simultaneously executing possibly related computations

  • dealing with lots of things vs. actively doing lots

not the same thing but they both need synchronisation.

New cards
13

what is a thread?

lightweight process, basic unit of CPU utilisation

New cards
14

what does a thread have?

  • a thread ID

  • a program counter

  • its own temporary data consisting of

    • a register set for data,

    • a stack to store variables

New cards
15

what do threads from the same process share?

  • a common memory space: made up of code section, data section, and other operating system resources (e.g. files, etc.).

New cards
16

how many threads does a traditional/ heavyweight process have

  • a single thread of control.

New cards
17

how do processes and threads relate?

  • processes are divided into threads, therefore, if a process has many threads it can perform more than one task at a time e.g. A web browser might have one thread that displays images or text while another thread retrieves data from the network.

New cards
18

when are applications single threaded or multithreaded?

applications are mainly multithreaded where many threads belonging to same process

<p>applications are mainly multithreaded where many threads belonging to same process</p>
New cards
19

what issues are there when threads share data?

  • data inconsistency - 2 threads sharing the same data and trying to update at same time, which is correct

New cards
20

in what situation would a single application need to perform many similar tasks?

  • A web server accepts client requests for web pages, images, sound etc.

  • A busy web server may have several clients concurrently accessing it.

New cards
21

what are the different methods are there to manage a single application that is required to perform many similar tasks?

  • a single threaded process using process creation

  • multithreaded server

New cards
22

how does a single threaded process work?

  • run the server as a single process used for accepting and servicing requests

  • Only manage one client at a time (might have to wait a very long time for its request to be serviced = not efficient

  • uses the process creation method

New cards
23

what is the Process-creation method?

  • When a server receives a request, it creates a separate process to service that request.

  • process creation is time consuming and resource intensive.

New cards
24

what is the purpose of multithreading?

The main purpose of multithreading is to provide simultaneous execution of two or more parts of a program aiming at maximising CPU time utilisation.

New cards
25

what is a multithreaded program?

A multithreaded program contains two or more parts that can run concurrently. Each such part of a program called thread.

New cards
26

how does a Multithreaded server work?

  • When a request is made, rather than creating another process, the server creates a new thread to service the request and resume listening for additional requests.

<ul><li><p>When a request is made, rather than creating another process, the server creates a new thread to service the request and resume listening for additional requests.</p></li></ul>
New cards
27

what other ways are multithreaded servers used?

  • remote procedure call, doing RPC using a multithreaded server allows interprocess communication and lets us service concurrent requests by creating a new thread after a message is received

  • multithreaded kernel where each thread does a specific task e.g. manage devices or managing memory.

New cards
28

what are the benefits of threads/ multithreaded server?

responsiveness

resource sharing

economy

scalability

[ra ra, emerging servers]

New cards
29

what is the responsiveness benefit?

  • Multithreading an interactive application may allow a program to continue running even if part of it is blocked or is performing a lengthy operation. a single-thread app would be unresponsive until user operation complete

  • eg. seeing what is displayed in web browser whilst in background retrieving data

New cards
30

what is the resource sharing benefit?

  • Processes can only share resources through techniques such as shared memory and message passing.

  • Threads share the memory and the resources of the process to which they belong by default - allows an application to have several different threads of activity within the same address space.

New cards
31

what is the economy benefit?

Allocating memory and resources for process creation is costly. Because threads share the resources of the process to which they belong, it is more economical (faster) to create and context-switch new threads rather than create new processes

New cards
32

what is the scalability benefit?

as the system gets larger e.g. multiprocessor architecture, can run faster and the benefits are better

  • threads may be running in parallel on different processing cores

  • a single-threaded process can run on only one processor, regardless of how many are available.

New cards
33

how many states can a thread be in at a given point in time?

only 1 state at a time

New cards
34

what are the different thread states?

new

runnable

blocked

waiting

timed waiting

terminated

New cards
35

what is the thread state diagram/ thread lifecycle?

knowt flashcard image
New cards
36

what is the new thread state?

A thread that has not yet started.

  • When a thread is created, it’s in NEW state. At this point, thread is not alive and it’s a state internal to Java programming. It remains in this state until the program starts the thread using it’s start() method.

<p>A thread that has not yet started.</p><ul><li><p>When a thread is created, it’s in NEW state. At this point, thread is not alive and it’s a state internal to Java programming. It remains in this state until the program starts the thread using it’s <mark data-color="blue">start()</mark> method.</p></li></ul>
New cards
37

what is the runnable thread state?

A thread executing in the Java virtual machine.

  • Calling start() method on thread puts it in RUNNABLE state. At this point, execution control is passed to thread scheduler to finish it’s execution.

  • The OS gives a small amount of processor time to each thread – called a quantum or timeslice – with which to perform its task.

<p>A thread executing in the Java virtual machine.</p><ul><li><p>Calling <mark data-color="blue">start()</mark> method on thread puts it in RUNNABLE state. At this point, execution control is passed to <mark data-color="yellow">thread scheduler</mark> to finish it’s execution.</p></li><li><p>The OS gives a small amount of processor time to each thread – called a <mark data-color="yellow">quantum or timeslice</mark> – with which to perform its task.</p></li></ul>
New cards
38

what is the blocked thread state?

A thread that is blocked waiting for a monitor lock.

  • A RUNNABLE thread transitions to the BLOCKED state when it attempts to perform a task that cannot be completed immediately and it must temporarily wait until that task completes

  • runnable → blocked = issue io request/ enter synchronized statement

  • blocked → runnable - inturrupt/ acquire lock/ io complete

<p>A thread that is blocked waiting for a monitor lock.</p><ul><li><p>A RUNNABLE thread transitions to the BLOCKED state when it <strong>attempts to perform a task that cannot be completed immediately</strong> and it must <strong>temporarily wait</strong> until that task completes</p></li><li><p><mark data-color="yellow">runnable → blocked = issue io request/ enter synchronized statement</mark></p></li><li><p><mark data-color="yellow">blocked → runnable - inturrupt/ acquire lock/ io complete</mark></p></li></ul>
New cards
39

what is the waiting thread state?

A thread that is waiting indefinitely for another thread to perform a particular action before it can continue its current action.

  • A thread can be put in waiting state for various reasons.

  • runnable → wait = wait()

  • wait → runnable = notify()/ notifyAll()

<p>A thread that is waiting indefinitely for another thread to perform a particular action before it can continue its current action.</p><ul><li><p>A thread can be put in waiting state for various reasons.</p></li><li><p><mark data-color="yellow">runnable → wait = wait()</mark></p></li><li><p><mark data-color="yellow">wait → runnable = notify()/ notifyAll()</mark></p></li></ul>
New cards
40

what is the timed waiting thread state?

A thread that is waiting for another thread to perform an action for up to a specified waiting time.

  • A RUNNABLE thread can transition to the TIMED WAITING state if it provides an optional wait interval

  • runnable → timedWait = sleep(millis)/ wait(millis)

  • timedWait → runnable = notify()/ notifyAll()/ waitIntervalExpires()

    • returns to the RUNNABLE state when it’s notified by another thread or when the timed interval expires – whichever comes first.

<p>A thread that is waiting for another thread to perform an action for up to a specified waiting time.</p><ul><li><p>A RUNNABLE thread can transition to the TIMED WAITING state if it provides an <strong>optional wait interval</strong></p></li><li><p><mark data-color="yellow">runnable → timedWait =  sleep(millis)/  wait(millis)</mark></p></li><li><p><mark data-color="yellow">timedWait → runnable = notify()/ notifyAll()/ waitIntervalExpires()</mark></p><ul><li><p>returns to the RUNNABLE state when it’s notified by another thread or when the timed interval expires – whichever comes first.</p></li></ul></li></ul>
New cards
41

what is the terminated thread state?

A thread that has exited.

  • A thread enters the TERMINATED state (sometimes called the dead state) when it successfully completes its task or otherwise terminated due to any error or even it was forcefully killed.

  • runnable → terminated = taskExpires()

<p>A thread that has exited.</p><ul><li><p>A thread enters the TERMINATED state (sometimes called the dead state) when it successfully completes its task or otherwise terminated due to any error or even it was forcefully killed.</p></li><li><p><mark data-color="yellow">runnable → terminated = taskExpires()</mark></p></li></ul>
New cards
robot