Process Management: Threads

studied byStudied by 1 person
5.0(1)
get a hint
hint

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

1 / 40

Tags & Description

Studying Progress

0%
New cards
41
Still learning
0
Almost done
0
Mastered
0
41 Terms
1
New cards

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
New cards

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
New cards

what combination of parallel and concurrent is SEQUENTIAL?

not parallel : not concurrent

New cards
4
New cards

what combination of parallel and concurrent is CONCURRENT?

not parallel : concurrent

New cards
5
New cards

what combination of parallel and concurrent is PARALLEL?

parallel : not concurrent

New cards
6
New cards

what is sequential execution?

<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>
  • 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
New cards

what is concurrent execution?

<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>

  • 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
New cards

what is parallel execution?

<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>
  • 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
New cards

what is parallel and concurrent execution?

<ul><li><p>eg. multiple CPUs means parallel tasks can run, but within each CPU the tasks run concurrently</p></li></ul>
  • 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
New cards

what is parallelism?

<ul><li><p>one application divided into subtasks that can be mapped to different CPUs, communication between the subtasks occurs</p></li></ul>
  • 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
New cards

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
New cards

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
New cards

what is a thread?

lightweight process, basic unit of CPU utilisation

New cards
14
New cards

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
New cards

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
New cards

how many threads does a traditional/ heavyweight process have

  • a single thread of control.

New cards
17
New cards

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
New cards

when are applications single threaded or multithreaded?

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

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
New cards

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
New cards

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
New cards

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
New cards

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
New cards

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
New cards

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
New cards

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
New cards

how does a Multithreaded server work?

<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>
  • 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
New cards

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
New cards

what are the benefits of threads/ multithreaded server?

responsiveness

resource sharing

economy

scalability

[ra ra, emerging servers]

New cards
29
New cards

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
New cards

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
New cards

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
New cards

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
New cards

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

only 1 state at a time

New cards
34
New cards

what are the different thread states?

new

runnable

blocked

waiting

timed waiting

terminated

New cards
35
New cards

what is the thread state diagram/ thread lifecycle?

knowt flashcard image
knowt flashcard image
New cards
36
New cards

what is the new thread state?

<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>

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
New cards

what is the runnable thread state?

<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>

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
New cards

what is the blocked thread state?

<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>

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
New cards

what is the waiting thread state?

<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>

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
New cards

what is the timed waiting thread state?

<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>

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
New cards

what is the terminated thread state?

<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>

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

Explore top notes

note Note
studied byStudied by 11 people
Updated ... ago
4.5 Stars(2)
note Note
studied byStudied by 1 person
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 19 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 10 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 30 people
Updated ... ago
4.3 Stars(3)
note Note
studied byStudied by 201 people
Updated ... ago
5.0 Stars(3)
note Note
studied byStudied by 103 people
Updated ... ago
5.0 Stars(2)
note Note
studied byStudied by 6645 people
Updated ... ago
5.0 Stars(3)

Explore top flashcards

flashcards Flashcard35 terms
studied byStudied by 18 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard104 terms
studied byStudied by 10 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard45 terms
studied byStudied by 8 people
Updated ... ago
4.0 Stars(1)
flashcards Flashcard81 terms
studied byStudied by 5 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard99 terms
studied byStudied by 6 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard31 terms
studied byStudied by 3 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard254 terms
studied byStudied by 141 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard100 terms
studied byStudied by 187 people
Updated ... ago
5.0 Stars(9)