0% found this document useful (0 votes)
13 views11 pages

HW 4

Uploaded by

owen0928092110
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views11 pages

HW 4

Uploaded by

owen0928092110
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

OS _

HW 4
B 104020046 單業儒
/ 3

User level threads are unknown by the


1
-

Kernel however the Kernel is aware of


, ,

Kernel threads .

On M M N
systems usingeither 1 or
mapping
: :

user threads are scheduled by the thread

library and the Kernel schedulesKernd threads ,

Kernel threads need not be associated with


a
process whereas every user thread belongs
to a process Kernel threads
.

aregenerally
more expensivetomaintain than user threads
because they must be represented with a

Kernel data structure


#
.
Multiple Kernel threads :

When kernel thread suffers


a a
page fault ,

another Kernel thread can be switched in to

use the
inferleaving time in a useful manner .

Single -

threaded process :

It will not be capable of performing useful


work when a
page fault happens Therefore
. ,

suffer
in scenarios where a
program might
from frequent page faults or has to waitfor
other
system events, a
mulithreadeds 0lution
would perform better even on a
single
processor system .

#
A : b ,
c

The threads of mulithreaded process share


a

heap memory and global variables Fach thread .

has its separate set of values and


register
a
separate stack ,

'

heapmemory

variables
global
吿 負責分配任務給threads 的系統

1 .
Pata parallelism 2 .
Data parallelism
3 . Task parallelism Data parallelism
4 .

5 .
Task parallelism1

!

'
sine file
the must be accessed sequentially
,
the work of reading and writing it cannot

be parallelized and only asingle


, thread
should be used for each of these tasks .

2
The CPU intensive porion should bedivided
-

eveuly among the four processors sofour


,

threads should be created for this part of the


program Fewer than four would waste processor
.

resources ,
while more threads would be
unable to run
simultaneously .

#

I
The initialcalltofork ( )creates aopy of
the original process ( 2 processes now ) ,

The second call to fork ( ) is executed onlyby


the child process from the first fork ( ) call
.

( 3 now )
processes ,

3
There two processes execuing the
are now

code insido the if statement s 0 both of ,

those processes call thread create ( -


)

( 3 processes 2 threads )
,
4
A 11 three processes execute the final call
to fork ( ) ,
so each
process opies itself at

that ( 6 2 threads )
point ,

processes ,
,

a 6
.

processes

b 2 threads
,

¢
LINEC =
5

LINEP =

The only time that a child process writing to memory also makes changes in
the parent process's memory is when the memory written to is explicitly
shared memory.

opy of parent process


child process is the ,

any thing changes child process will not affect


in

the parent (
process they don't have shared
momory) .

Threads share the same memory space S 0 ,


the

threads in the child modifies the memory that the


child's main thread has access to ,
a .
Because the number of Korne1 threads is
less than the number of processingcores ,

so the cores which are not be scheduled will


be idle

b lan of processing
.

fully ultilize the resource

cores . ( If some Kerne1 threads are stuck by


user -
level I10 threads they still can not
,

fully ultilired .
)

c .
All of the processes will be working
simultaneously assuming there
areenough
user threads .
If a Kerne 1 thread is blocked ,

it be swapped out for one that isnt


may
blocked .

You might also like