Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Реферат - Потоки / lab4thread2 / mutex4 / thrd
.pas unit thrd;
interface
uses
Classes,Graphics,Windows,SysUtils,StdCtrls,syncobjs;
type
tmythread = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
public
Count : Integer;
s:string;
end;
implementation
uses trd;
{ Important: Methods and properties of objects in VCL or CLX can only be used
in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure tmythread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
{ tmythread }
procedure tmythread.Execute;
Var
i, ob, sr : Integer;
begin
if waitforsingleobject(mut,infinite)=wait_object_0 then
begin
While True Do Begin ob := 0;
For i := 1 To 10 Do
//Inc ( ob, Random( Maxint ));
inc(ob,round(sqrt(abs(sin(i)))));
sr := sr Div 10;
Inc( Count ) ;
s:='Hello from threadland';
releasemutex(mut);
end;
// with Critical do begin
// enter;
//showmessage(form1.Edit3.Handle,WM_Settext,0,integer(pchar(s)));
//leave;
End;
end;
//end;
end.
interface
uses
Classes,Graphics,Windows,SysUtils,StdCtrls,syncobjs;
type
tmythread = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
public
Count : Integer;
s:string;
end;
implementation
uses trd;
{ Important: Methods and properties of objects in VCL or CLX can only be used
in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure tmythread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
{ tmythread }
procedure tmythread.Execute;
Var
i, ob, sr : Integer;
begin
if waitforsingleobject(mut,infinite)=wait_object_0 then
begin
While True Do Begin ob := 0;
For i := 1 To 10 Do
//Inc ( ob, Random( Maxint ));
inc(ob,round(sqrt(abs(sin(i)))));
sr := sr Div 10;
Inc( Count ) ;
s:='Hello from threadland';
releasemutex(mut);
end;
// with Critical do begin
// enter;
//showmessage(form1.Edit3.Handle,WM_Settext,0,integer(pchar(s)));
//leave;
End;
end;
//end;
end.