...
This presentation is the property of its rightful owner.
Sponsored Links
1 / 40

この資料は、情報工学レクチャーシリーズ オペレーティングシステム 松尾啓志 著(森北出版株式会社)を用いて授業を行うために、名古屋工業大学松尾啓志、津邑公暁が作成しました。 PowerPoint PPT Presentation


  • 48 Views
  • Uploaded on
  • Presentation posted in: General

この資料は、情報工学レクチャーシリーズ オペレーティングシステム 松尾啓志 著(森北出版株式会社)を用いて授業を行うために、名古屋工業大学松尾啓志、津邑公暁が作成しました。 パワーポイント 2007 で最終版として保存しているため、変更はできませんが、授業でお使いなる場合は松尾 ([email protected]) まで 連絡いただければ、編集可能なバージョンをお渡しする事も可能です。. オペレーティングシステム #6 並行プロセス:モニタ. 復習:セマフォ. 排他制御の枠組み P 命令 リソース獲得要求,失敗時には待ち状態に移行 V 命令

Download Presentation

この資料は、情報工学レクチャーシリーズ オペレーティングシステム 松尾啓志 著(森北出版株式会社)を用いて授業を行うために、名古屋工業大学松尾啓志、津邑公暁が作成しました。

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


5965240

2007([email protected])


5965240

#6


5965240

  • P

  • V


5965240

  • Producer-Consumer

  • Reader-Writer

  • Dining Philosophers


5965240

6.1


5965240

    • P

    • V

      • PV


5965240

    • Java


5965240

  • ...


5965240

6.2


5965240

    • C++

    • Java

    • Smalltalk

    • Objective-C

    • Python(?)

    • Ruby(?)


5965240

  • class

  • method

  • instance


5965240

class {

;

;

;

;

:

:

}


5965240

    • = 0;

    • += n;

    • = on;

    • if (){ ... };

    • = on;

class {

;

;

;

;

:

:

}


5965240

class {

public:

(n){

= 0;

+= n;

= on;

if( ){ ... }

}

private:

;

;

;

;

:

:

}


5965240

class {

public:

( n ){

:

}

:

private:

:

}

A;

main(){

A.(10);

}


5965240

6.3


5965240


5965240

  • wait / signal / queue

  • ...


5965240

monitor{

public:

use_resource1(n){

1 += n;

}

use_resource2(){

:

}

:

private:

1;

2;

:

:

}


5965240

  • AB

    • B

    • AB

A

B


5965240

monitor Shared_I {

private:

int I;

public:

increment( amount ){

I += amount;

}

decrement( amount ){

I -= amount;

}

}

Shared_Inum;

num.decrement(1);

;

num.increment(1);

num.decrement(1);

;

num.increment(1);


5965240

  • 1

Writer

Writer

Writer

Reader

Reader

Reader

Database


5965240

1

monitor Reader_Writer_1{

private:

int Readers = 0;

int Writers = 0;

boolean busy = FALSE;

public:

start_read(){

while(Writers!=0){};

Readers += 1;

}

finish_read(){

Readers -= 1;

}

start_write(){

Writers += 1;

while( busy ||

Readers!=0 ){};

busy = TRUE;

}

finish_write(){

Writers -= 1;

busy = FALSE;

}

}

Reader_Writer_1 lock;

lock.start_write();

DB;

lock.finish_write();

lock.start_read();

DB;

lock.finish_read();


5965240

    • wait

    • signal

      • 1

    • queue


5965240

  • wait

  • signal

    • 1

  • queue

class condition{

private:

;

public:

wait(){

;

}

signal(){

;

}

queue(){

if( > 0 )

return TRUE;

else

return FALSE;

}

}


5965240

monitor Reader_Writer_2{

private:

int Readers = 0;

int Writers = 0;

condition OK_read, OK_write;

public:

start_read(){

if( busy || OK_write.queue())

OK_read.wait();

Readers += 1;

while( OK_read.queue())

OK_read.signal();

}

finish_read(){

Readers -= 1;

if( Readers == 0 )

OK_write.signal();

}

start_write(){

if( Readers != 0 || busy )

OK_write.wait();

busy = TRUE;

}

finish_write(){

busy = FALSE;

if( OK_read.queue() )

OK_read.signal();

else

OK_write.signal();

}

}

class condition{

public:

wait(){ ... }

signal(){ ... }

queue(){ ... }

}


5965240

  • P

  • V

    • 1

  • wait

  • signal

    • 1

  • queue


5965240

    • P

    • wait


5965240


5965240

msg

msg

A

B

msg

msg

msg


5965240

A

B

monitor Producer_Consumer{

private:

Messages Buffer[N];

int S, M;

condition Full, Empty;

int Count;

public:

producer( word ){

if( Count == N )

Full.wait();

Buffer[S] = word;

S = (S + 1) mod N;

Count += 1;

Empty.signal();

}

consumer( word ){

if( Count == 0 )

Empty.wait();

word = Buffer[M];

M = (M + 1) mod N;

Count = Count 1;

Full.signal();

}

}

Full wait

Empty


Dining philosophers

Dining Philosophers

EATING

enum{ EATING, HUNGRY, THINKING };

monitor Dining_Philosophers{

private:

state[N];

condition self[N];

test( i ){

if( (state[(i-1) mod N] != EATING)

&& (state[i] == HUNGRY)

&& (state[(i+1) mod N] != EATING) ){

state[i] = EATING;

self[i].signal();

}

}

public:

up( i ){

state[i] = HUNGRY;

test( i );

if( state[i] != EATING )

self[i].wait();

}

down( i ){

state[i] = THINKING;

test( (i-1) mod N );

test( (i+1) mod N );

}

}

wait

HUNGRY

EATING

signal


5965240

    • signal()/wait()

      • Java


5965240


5965240

(1/5)

    • OS

    • /


5965240

(2/5)

  • (MUTEX)

    • Dekker


5965240

(3/5)

Interest

  • Dekker

    • Interest

    • Priority


5965240

P!

V!

(4/5)

    • P

    • V

      • V

      • Dining Philosopher


5965240

(5/5)

class {

public:

(n){

= 0;

+= n;

= on;

if( ){ ... }

}

private:

;

;

;

;

:

:

}


5965240


  • Login