Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
22
Добавлен:
05.06.2015
Размер:
2 Кб
Скачать
☆
Program ceom6;

uses sysutils,windows,math;

const N=1000000;

type
  BigArray=array [0..N] of integer;

var
  MyBigArray:^BigArray;

function MyThread(p:pointer):PtrInt;
var q:^LongInt;
    i:LongInt;
    x:single;
    a,b:integer;
begin
  a:=10; x:=0;
  q:=p;
  writeLn('My number is: ',q^);
  i:=q^;
  q^:=0;
  while i<N do
  begin
  x:=MyBigArray^[i]/(sqr(MyBigArray^[i])+1);
   
    q^:=(q^+round(x)) and $FF;
    i:=i+2;
  end;
end;

function MyThread2(p:pointer):PtrInt;
var q:^LongInt;
    i,MAX:LongInt;
    x:single;
    a,b:integer;
begin
  a:=4; x:=0;
  q:=p;
  writeLn('My number is: ',q^);
  i:=q^*(N div 2);
  MAX:=i+(N div 2);
  q^:=0;
  while i<MAX do
  begin
   x:=MyBigArray^[i]/(sqr(MyBigArray^[i])+1);
    q^:=(q^+round(x)) and $FF;

    i:=i+1;
  end;
end;


Var q1,q2:LongInt;
    ID1,ID2:TThreadID;
    T,k,ty:LongInt;

Begin
  new(MyBigArray);
  if MyBigArray<>nil then
  begin
    randomize;
    for T:=0 to N do MyBigArray^[T]:=random(100);
    Write('Vvedit potochnist (0-odin,1-dva potoki):');
    ReadLn(k);
    Write('Vvedit tip rozrahunkiv (0-cherez odin,1-po polovine):');
    ReadLn(ty);
    q1:=0; q2:=1;
    T:=GetTickCount();
    if(k=0)then
       begin
        if(ty=0) then
           begin
        ID1:=BeginThread(@MyThread,@q1);
        WaitForThreadTerminate(ID1,100000);
        ID2:=BeginThread(@MyThread,@q2);
        WaitForThreadTerminate(ID2,100000);
     		 end else begin
        ID1:=BeginThread(@MyThread2,@q1);
        WaitForThreadTerminate(ID1,100000);
        ID2:=BeginThread(@MyThread2,@q2);
        WaitForThreadTerminate(ID2,100000);
      end;
    		 end else begin
      if(ty=0)then begin
        ID1:=BeginThread(@MyThread,@q1);
        ID2:=BeginThread(@MyThread,@q2);
        WaitForThreadTerminate(ID1,100000);
        WaitForThreadTerminate(ID2,100000);
      end else begin
        ID1:=BeginThread(@MyThread2,@q1);
        ID2:=BeginThread(@MyThread2,@q2);
        WaitForThreadTerminate(ID1,100000);
        WaitForThreadTerminate(ID2,100000);
      end;
    end;
    WriteLn('The task performed by: ',GetTickCount()-T,' ms');
    dispose(MyBigArray);
  end else
  begin
    writeln('Error allocation the memory!');
  end;
End.
Соседние файлы в папке цеом