Тапсырмасының программасының листингі

unit Critsec;

interface

uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

StdCtrls;

type

TForm1 = class(TForm)

Button1: TButton; ListBox1: TListBox; ListBox2: TListBox;

CheckBox1: TCheckBox;

procedure FormCreate(Sender: TObject);

procedure FormDestroy(Sender: TObject);

procedure Button1Click(Sender: TObject);

end;

var

Form1 : TForm1;

crits : boolean;

sect1 : TRTLCriticalSection;

global: word;

// 2 // hmut : thandle;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);

begin

initializeCriticalSection(sect1);

// 2 // hmut := createmutex(nil,true,nil);

end;

procedure TForm1.FormDestroy(Sender: TObject);

begin

DeleteCriticalSection(sect1);

//2// closehandle(hmut);

end;

function Thr1 (p:pointer):longint; stdcall;

var i,j : integer;

begin

form1.listbox1.items.clear;

for j:=1 to 12 do

begin

if crits then

EnterCriticalSection (sect1);

//2// waitforsingleobject(hmut,infinite);

sleep(10);

i:=global; i:=i+1;

form1.listbox1.items.add(intToStr(i));

global:=i;

if crits then

LeaveCriticalSection(sect1);

//2// releasemutex(hmut);

end;

end;

function Thr2 (p:pointer):longint; stdcall;

var i,j : integer;

begin

form1.listbox2.items.clear;

for j:=1 to 12 do

begin

if crits then

EnterCriticalSection (sect1);

//2// waitforsingleobject(hmut,infinite);

sleep(7);

i:=global; i:=i+1;

form1.listbox2.items.add(intToStr(i));

global:=i;

if crits then

LeaveCriticalSection(sect1);

//2// releasemutex(hmut);

end;

end;

procedure TForm1.Button1Click(Sender: TObject);

var thrid : dword;

thrh1,thrh2: thandle;

begin

global:= 100;

if CheckBox1.Checked then crits:= true

else crits:= false ;

thrh1:=CreateThread(nil,0,@Thr1,nil,0,thrid);

thrh2:=CreateThread(nil,0,@Thr2,nil,0,thrid);

end;

end.

В қосымшасы

Тапсырмаға арналған программа листингі

#include

#include

#include

#include

#include

int main(char*argv[])

{clrscr();

char ch;

cout<<"to zadach1 - 1"<

cout<<"to zadach2 - 2"<

cout<<"to zadach3 - 3"<

cout<<"to quit - q"<

cin>>ch;

while(ch!='q')

{switch(ch)

{case '1':execv("task1.exe",argv);

case '2':execv("task2.exe",argv);

case '3':execv("3.exe",argv);

case 'q':exit(1);

default:cout<<"net"<

//execv(@rever/exe@?argv)$

return 0; }

#include

#include

void main()

{float x,y;int i;

for(i=0;i<=20;i++)

{x=i*0.157;

y=sin(x);

cout<

cout<

}

#include

#include

#include

void main()

{float x,y; int i;

for(i=0;i<=20;i++)

{x=i*0.157;

y=cos(x);

cout<

cout<

}


4488693864718945.html
4488727936330005.html
    PR.RU™