Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Архив1 / docx31 / Отчет (3).docx
Скачиваний:
96
Добавлен:
01.08.2013
Размер:
606.3 Кб
Скачать

UnitUnit2

Interface

uses

Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,

Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, JvExStdCtrls, JvGroupBox,

Vcl.Samples.Spin, Vcl.ExtCtrls;

type

TForm2 = class(TForm)

JvGroupBox1: TJvGroupBox;

JvGroupBox2: TJvGroupBox;

JvGroupBox3: TJvGroupBox;

JvGroupBox4: TJvGroupBox;

JvGroupBox5: TJvGroupBox;

SpinEdit1: TSpinEdit;

Label1: TLabel;

SpinEdit2: TSpinEdit;

Label2: TLabel;

SpinEdit3: TSpinEdit;

SpinEdit4: TSpinEdit;

Label3: TLabel;

Label4: TLabel;

SpinEdit5: TSpinEdit;

SpinEdit6: TSpinEdit;

Label5: TLabel;

Label6: TLabel;

SpinEdit7: TSpinEdit;

SpinEdit8: TSpinEdit;

Label7: TLabel;

Label8: TLabel;

SpinEdit9: TSpinEdit;

SpinEdit10: TSpinEdit;

Label9: TLabel;

Label10: TLabel;

Timer1: TTimer;

Label11: TLabel;

Label12: TLabel;

Label13: TLabel;

Label14: TLabel;

Label15: TLabel;

Label16: TLabel;

Label17: TLabel;

Label18: TLabel;

Label19: TLabel;

Label20: TLabel;

JvGroupBox6: TJvGroupBox;

Button1: TButton;

Button2: TButton;

Button3: TButton;

Button4: TButton;

SpinEdit11: TSpinEdit;

Label21: TLabel;

SpinEdit12: TSpinEdit;

Label22: TLabel;

procedure SpinEdit1Change(Sender: TObject);

procedure Timer1Timer(Sender: TObject);

procedure Button1Click(Sender: TObject);

procedure Button2Click(Sender: TObject);

procedure Button4Click(Sender: TObject);

procedure Button3Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form2: TForm2;

Implementation

{$R *.dfm}

uses Unit1;

procedure TForm2.Button1Click(Sender: TObject);

var i:integer;

begin

while WaitForSingleObject(Unit1.VilkaHandle,1)<>WAIT_TIMEOUT do ; // Убираем все вилки и ножи со стола

while WaitForSingleObject(Unit1.NojHandle,1)<>WAIT_TIMEOUT do ;

for i:=1 to nFil do TimeGolodovka[i]:=0;

VilkaCnt:=SpinEdit11.Value;

NojCnt:=SpinEdit12.Value;

ReleaseSemaphore(Unit1.VilkaHandle,SpinEdit11.Value,nil); // Кладем чистые вилки и ножи

ReleaseSemaphore(Unit1.NojHandle,SpinEdit12.Value,nil);

for i:=1 to nFil do Filosofs[i].Start;

end;

procedure TForm2.Button2Click(Sender: TObject);

var i:integer;

begin

for i:=1 to nFil do Filosofs[i].Stop;

end;

procedure TForm2.Button3Click(Sender: TObject);

begin

Application.MessageBox('Курсовая работа по Операционным Системам' + #13#10 +

'на тему:' + #13#10#13#10 + '"Разработка ПО для решения задачи ' +

#13#10 + '"обедающих философов" с использованием ' + #13#10 +

'синхронизации с помощью семафоров"' + #13#10#13#10 +

'Выполнил: ст. гр. ПВ-32' + #13#10 + 'Юсюмбели Н. И',

'Информация о программе', MB_OK + MB_ICONINFORMATION + MB_TOPMOST);

end;

procedure TForm2.Button4Click(Sender: TObject);

begin

Application.Terminate;

end;

procedure TForm2.SpinEdit1Change(Sender: TObject);

var k:integer;

begin

k:=(Sender as TComponent).Tag;

if k>10 then

begin

k:=k-10;

Unit1.Filosofs[k].TimeToEat:=(Sender as TSpinEdit).Value;

end else Unit1.Filosofs[k].TimeToThink:=(Sender as TSpinEdit).Value;

end;

procedure TForm2.Timer1Timer(Sender: TObject);

var i,sum:integer;

begin

SpinEdit1.Value:=Unit1.Filosofs[1].TimeToThink;

SpinEdit3.Value:=Unit1.Filosofs[2].TimeToThink;

SpinEdit5.Value:=Unit1.Filosofs[3].TimeToThink;

SpinEdit7.Value:=Unit1.Filosofs[4].TimeToThink;

SpinEdit9.Value:=Unit1.Filosofs[5].TimeToThink;

SpinEdit2.Value:=Unit1.Filosofs[1].TimeToEat;

SpinEdit4.Value:=Unit1.Filosofs[2].TimeToEat;

SpinEdit6.Value:=Unit1.Filosofs[3].TimeToEat;

SpinEdit8.Value:=Unit1.Filosofs[4].TimeToEat;

SpinEdit10.Value:=Unit1.Filosofs[5].TimeToEat;

for i:=1 to nFil do

if Unit1.Filosofs[i].State = 2 then inc(Unit1.TimeGolodovka[i]);

sum:=0;

for i:=1 to nFil do

sum:=sum+Unit1.TimeGolodovka[i];

if sum=0 then sum:=1;

Label12.Caption:=Format('%d [%.0f%%] сек.',[Unit1.TimeGolodovka[1],Unit1.TimeGolodovka[1]/sum*100]);

Label14.Caption:=Format('%d [%.0f%%] сек.',[Unit1.TimeGolodovka[2],Unit1.TimeGolodovka[2]/sum*100]);

Label16.Caption:=Format('%d [%.0f%%] сек.',[Unit1.TimeGolodovka[3],Unit1.TimeGolodovka[3]/sum*100]);

Label18.Caption:=Format('%d [%.0f%%] сек.',[Unit1.TimeGolodovka[4],Unit1.TimeGolodovka[4]/sum*100]);

Label20.Caption:=Format('%d [%.0f%%] сек.',[Unit1.TimeGolodovka[5],Unit1.TimeGolodovka[5]/sum*100]);

end;

end.

Соседние файлы в папке docx31