SS-02 Procesi

Embed Size (px)

Citation preview

  • 7/31/2019 SS-02 Procesi

    1/83

    1

    (Processes)

    (Threads)

    2.1 2.2

    2.3 -

    2.4 -

    2.5

  • 7/31/2019 SS-02 Procesi

    2/83

    2

    .

  • 7/31/2019 SS-02 Procesi

    3/83

    3

    Multiprogramming 4

  • 7/31/2019 SS-02 Procesi

    4/83

    4

    1.

    2. 3.

    4. batch job

  • 7/31/2019 SS-02 Procesi

    5/83

    5

    1. ()

    2. ()3. ()

    4. ()

  • 7/31/2019 SS-02 Procesi

    6/83

    6

    ,

    UNIX

    Windows

    .

  • 7/31/2019 SS-02 Procesi

    7/83

    7

    runningblocked

    ready

  • 7/31/2019 SS-02 Procesi

    8/83

    8

  • 7/31/2019 SS-02 Procesi

    9/83

    9

  • 7/31/2019 SS-02 Procesi

    10/83

    10

  • 7/31/2019 SS-02 Procesi

    11/83

    11

    (Threads)

    (Multithreading)

    (

    )

  • 7/31/2019 SS-02 Procesi

    12/83

    12

    (a)

    (b)

  • 7/31/2019 SS-02 Procesi

    13/83

    13

  • 7/31/2019 SS-02 Procesi

    14/83

    14

    ,

    Thread_create(__)

  • 7/31/2019 SS-02 Procesi

    15/83

    15

    thread_create thread_exit

    thread_wait

    thread_yield

    /

  • 7/31/2019 SS-02 Procesi

    16/83

    16

    :

  • 7/31/2019 SS-02 Procesi

    17/83

    17

    : Web Server

  • 7/31/2019 SS-02 Procesi

    18/83

    18

    : Web Server

    (a) Dispatcher thread

    (b) Worker thread

  • 7/31/2019 SS-02 Procesi

    19/83

    19

    :

    Web Server

  • 7/31/2019 SS-02 Procesi

    20/83

    20

  • 7/31/2019 SS-02 Procesi

    21/83

    21

  • 7/31/2019 SS-02 Procesi

    22/83

    22

    page fault

  • 7/31/2019 SS-02 Procesi

    23/83

    23

  • 7/31/2019 SS-02 Procesi

    24/83

    24

  • 7/31/2019 SS-02 Procesi

    25/83

    25

    Single-Threaded Multithreaded

  • 7/31/2019 SS-02 Procesi

    26/83

    26

    Single-Threaded Multithreaded

  • 7/31/2019 SS-02 Procesi

    27/83

    27

    Single-Threaded Multithreaded

    :

  • 7/31/2019 SS-02 Procesi

    28/83

    28

    (Interprocess Communication IPC)

  • 7/31/2019 SS-02 Procesi

    29/83

    29

    (Race Conditions)

    (C iti l

  • 7/31/2019 SS-02 Procesi

    30/83

    30

    (Critical

    Regions)

    .

    .

    (mutual exclusion)

    1.

    2.

    3.

    4.

  • 7/31/2019 SS-02 Procesi

    31/83

    31

  • 7/31/2019 SS-02 Procesi

    32/83

    32

    (busy waiting)

    Peterson

    TSL

  • 7/31/2019 SS-02 Procesi

    33/83

    33

    wait for turn = 0 ( 3 )

    noncritical_region (finish)

    noncritical_region (enter)

    turn = 1

    critical_region (finish)

    critical_region (enter)

    noncritical_region (enter)wait for turn = 0

    turn = 0 1 0

  • 7/31/2019 SS-02 Procesi

    34/83

    34

    Peterson

  • 7/31/2019 SS-02 Procesi

    35/83

    35

    TLS (Test and Set Lock)

    TSL RX, lock

    lock RX, lock

    1.

  • 7/31/2019 SS-02 Procesi

    36/83

    36

    XCHG

    XCHG x86

    (Sleep)

  • 7/31/2019 SS-02 Procesi

    37/83

    37

    (Sleep)

    (Wakeup)

    Peterson TSL /

    (Sleep)

  • 7/31/2019 SS-02 Procesi

    38/83

    38

    (Sleep)

    (Wakeup)

    (Producer-consumer)

    count =N => sleep

    insert_intem()

    count=0 => sleep

    wait for next item

    consumer is not

    sleeping (signal is

    lost)

    wakeup(consumer

    )

    count++

    instert_item()

    count=0,

    read_count

    ConsumerProducer

  • 7/31/2019 SS-02 Procesi

    39/83

    39

    Down: ,

    Up: 1, , down . 0.

    .

  • 7/31/2019 SS-02 Procesi

    40/83

    40

  • 7/31/2019 SS-02 Procesi

    41/83

    41

    Mutexes

    mutex_lock

    mutex_unlock

  • 7/31/2019 SS-02 Procesi

    42/83

    42

    mutex-

    ,

  • 7/31/2019 SS-02 Procesi

    43/83

    43

  • 7/31/2019 SS-02 Procesi

    44/83

    44

    (condition

    variables)

    wait

    signal

    ?

    signal

    signal

  • 7/31/2019 SS-02 Procesi

    45/83

    45

    JAVA

  • 7/31/2019 SS-02 Procesi

    46/83

    46

    : JAVA

    synchronized .

    JAVA synchronized ,

    synchronized

    wait = sleep notify = wakeup

    JAVA

  • 7/31/2019 SS-02 Procesi

    47/83

    47

    : JAVA

    : JAVA

  • 7/31/2019 SS-02 Procesi

    48/83

    48

    : JAVA

    -

  • 7/31/2019 SS-02 Procesi

    49/83

    49

    Send (destination, &message)

    Receive (source, &message)

  • 7/31/2019 SS-02 Procesi

    50/83

    50

    N

  • 7/31/2019 SS-02 Procesi

    51/83

    51

    MPI (Message Passing Interface)

  • 7/31/2019 SS-02 Procesi

    52/83

    52

  • 7/31/2019 SS-02 Procesi

    53/83

    53

    deadlock ?

  • 7/31/2019 SS-02 Procesi

    54/83

    54

  • 7/31/2019 SS-02 Procesi

    55/83

    55

    ( 1)

  • 7/31/2019 SS-02 Procesi

    56/83

    56

    ( 2)

  • 7/31/2019 SS-02 Procesi

    57/83

    57

  • 7/31/2019 SS-02 Procesi

    58/83

    58

  • 7/31/2019 SS-02 Procesi

    59/83

    59

  • 7/31/2019 SS-02 Procesi

    60/83

    60

    (Scheduling)

  • 7/31/2019 SS-02 Procesi

    61/83

    61

    (Sc edu g)

    ready CPU

    (scheduler)

  • 7/31/2019 SS-02 Procesi

    62/83

    62

    CPU I/O .

    ) CPU-bound process

    ) I/O bound process

  • 7/31/2019 SS-02 Procesi

    63/83

  • 7/31/2019 SS-02 Procesi

    64/83

    64

    Batch

    InteractiveReal-Time

  • 7/31/2019 SS-02 Procesi

    65/83

    65

  • 7/31/2019 SS-02 Procesi

    66/83

    66

    (throughput)

    (turnaround time)

    CPU

    (response time)

    Batch

  • 7/31/2019 SS-02 Procesi

    67/83

    67

    Batch-

    (Firs-Come First-Served)

    (Shortest Job First)

    (Shortest Remaining Time Next)

    (Firs Come First Served)

  • 7/31/2019 SS-02 Procesi

    68/83

    68

    (Firs-Come First-Served)

    .

    :

    CPU-bound 1 I/O , I/O-bound

    1000 I/O

    CPU

    I/O-bound 1000 .

    CPU-bound 10ms

    I/O-bound 10 .

    (Shortest Job First)

  • 7/31/2019 SS-02 Procesi

    69/83

    69

    (Shortest Job First)

    ) 14 .

    ) 11 .

    (Shortest Remaining Time Next)

  • 7/31/2019 SS-02 Procesi

    70/83

    70

    (Shortest Remaining Time Next)

    Batch

  • 7/31/2019 SS-02 Procesi

    71/83

    71

    Batch

  • 7/31/2019 SS-02 Procesi

    72/83

    72

    Round-Robin

    Priority Scheduling

    Multiple Queues

    Shortest Process Next

    Guaranteed Scheduling

    Lottery Scheduling Fair-Share Scheduling

    Round-Robin

  • 7/31/2019 SS-02 Procesi

    73/83

    73

    ) runnable

    ) runnable B

    (quantum)

    (Priority Scheduling)

  • 7/31/2019 SS-02 Procesi

    74/83

    74

    (Priority Scheduling)

    (Multiple Queues)

  • 7/31/2019 SS-02 Procesi

    75/83

    75

    (Multiple Queues)

    8-3

    4-2

    2-1

    1

    (Shortest Process Next)

  • 7/31/2019 SS-02 Procesi

    76/83

    76

    (S o es ocess e )

    (Guaranteed Scheduling)

  • 7/31/2019 SS-02 Procesi

    77/83

    77

    ( g)

    (Lottery Scheduling)

  • 7/31/2019 SS-02 Procesi

    78/83

    78

    ( y g)

    /

    1 .

    .

    ,

    -

    (Fair-Share Scheduling )

  • 7/31/2019 SS-02 Procesi

    79/83

    79

    ( g )

    4 ,,, ...

    ...

    Real-Time

  • 7/31/2019 SS-02 Procesi

    80/83

    80

    m

    i Pi Ci

    1

    1m

    i

    i i

    C

    P=

  • 7/31/2019 SS-02 Procesi

    81/83

    81

    :

    ( )

    ( )

  • 7/31/2019 SS-02 Procesi

    82/83

    82

  • 7/31/2019 SS-02 Procesi

    83/83

    83