Sortowanie bąbelkowe w dwóch wątkach. SIGSEGV w wątkach.

0

Dostałem świra i stwierdziłem, że zaimplementuje sobie sortowanie bąbelkowe w dwóch wątkach. Pomińmy fakt wydajności i sensu takiej implementacji a zajmijmy się kodem.

I od kodu zacznijmy:

unit BSort;

{==============================================================================}

{$mode objfpc}{$H+}

{==============================================================================}

interface

{==============================================================================}

uses
  Classes, SysUtils;

{==============================================================================}

type
  TcompFunc = function(AValue1, AValue2 : Integer) : boolean;

{==============================================================================}

procedure BubbleSort(var AMatrix : array of Integer; ACompFunc : TCompFunc);
function V1LargerV2(AValue1, AValue2 : Integer) : Boolean;

{==============================================================================}

implementation

{==============================================================================}

procedure Swap(var AValue1, AValue2 : Integer);
var
  Tmp : Integer;
begin
  Tmp := AValue1;
  AValue1 := AValue2;
  AValue2 := Tmp;
end;

{==============================================================================}

function V1LargerV2(AValue1, AValue2 : Integer) : Boolean;
begin
  result := false;
  if AValue1 > AValue2 then
    result := true;
end;

{------------------------------------------------------------------------------}

procedure BubbleSort(var AMatrix : array of Integer; ACompFunc : TCompFunc);
var
  i,j : Word;
begin
  for i := Low(AMatrix) to High(AMatrix) do
    for j := Low(AMatrix) to High(AMatrix) do
    begin
      if ACompFunc(AMatrix[j], AMatrix[j+1]) then
        Swap(AMatrix[j], AMatrix[j+1]);
    end;
end;

{==============================================================================}

end.
unit MultiThreadSort;

{==============================================================================}

{$mode objfpc}{$H+}

{==============================================================================}

interface

{==============================================================================}

uses
  Classes, SysUtils, BSort;

{==============================================================================}

type
  TData = array of integer;
  PData = ^TData;

{------------------------------------------------------------------------------}

type
  TSort = class(TThread)
      FMatrix : PData;
    protected
      procedure Execute; override;
    public
      constructor Create(var AMatrix : array of Integer);
    public
      property Terminated;
  end;

{==============================================================================}

implementation

{==============================================================================}

constructor TSort.Create(var AMatrix : array of Integer);
begin
  inherited Create(False);
  FreeOnTerminate := False;
  FMatrix := @AMatrix;
end;

{------------------------------------------------------------------------------}

procedure TSort.Execute;
begin
  BubbleSort(FMatrix^, @V1LargerV2);
end;

{==============================================================================}

end.
program sortuj;

{==============================================================================}

{$mode objfpc}{$H+}

{==============================================================================}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes, SysUtils, MultiThreadSort, BSort, Crt;

{==============================================================================}

const
  Max = 1000;

{==============================================================================}

var
  Start  : Double;
  Stop   : Double;
  Time   : array[0..1] of Double;
  Matrix : array[0..9,0..Max] of integer;
  i,j    : Word;

{==============================================================================}

procedure Sort(var AMatrix : array of Integer);
var
  Sort    : array[0..1] of TSort;
  Matrix  : array[0..1] of array of Integer;
  Highest : Integer;
  i, j, k : Word;
begin
  Highest := Low(Integer);
  for i := Low(AMatrix) to High(AMatrix) do
    if AMatrix[i] > Highest then
      Highest := AMatrix[i];

  for i := 0 to 1 do
    SetLength(Matrix[i], Length(AMatrix) div 2);

  j := 0;
  k := 0;
  for i := Low(AMatrix) to High(AMatrix) do
    if AMatrix[i] < Highest div 2 then
    begin
      Matrix[0,j] := AMatrix[i];
      Inc(j);
    end
    else
    begin
      Matrix[1,k] := AMatrix[i];
      Inc(k);
    end;

  for i := 0 to 1 do
    Sort[i] := TSort.Create(Matrix[i]);

  for i := 0 to 1 do
    if not Sort[i].Terminated then sleep(2);

  for i := 0 to 1 do
    FreeAndNil(Sort[i]);

  k := 0;
  for i := 0 to 2 do
    for j := Low(Matrix[i]) to High(Matrix[i]) do
    begin
      AMatrix[k] := Matrix[i,j];
      Inc(k);
    end;
end;

{==============================================================================}

begin
  Randomize;
  ClrScr;

  for i := 0 to 9 do
  begin
    Write('Losowanie ', i, ' tablicy...');
    for j := 0 to Max do
      Matrix[i,j] := Random(60000) - 30000;
    Writeln('Wylosowana');
  end;

  Writeln;
  Start := TimeStampToMsecs(DateTimeToTimeStamp(Now));
  for i := 0 to 9 do
  begin
    Write('Sortowanie ', i, 'tablicy...');
    BubbleSort(Matrix[i],@V1LargerV2);
    Writeln('Posortowana');
  end;
  Stop := TimeStampToMsecs(DateTimeToTimeStamp(Now));
  Time[0] := Stop - Start;

  Writeln;
  for i := 0 to 9 do
  begin
    Write('Losowanie ',i,' tablicy...');
    for j := 0 to Max do
      Matrix[i,j] := Random(60000) - 30000;
    Writeln('Wylosowana');
  end;

  Writeln;
  Start := TimeStampToMsecs(DateTimeToTimeStamp(Now));
  for i := 0 to 9 do
  begin
    Write('Sortowanie dwuwątkowe', i, ' tablicy...');
    Sort(Matrix[i]);
    Writeln('Posortowana');
  end;
  Stop := TimeStampToMsecs(DateTimeToTimeStamp(Now));
  Time[1] := Stop - Start;

  Writeln;
  Writeln('Sortowanie bąbelkowe : ',Time[0]);
  Writeln('Sortowanie dwuwątkowe: ',Time[1]);
  Readln;
end.

No i przy tworzeniu dwóch wątków wywala SIGSEGV :( zawsze miałem problem z wątkami i nie wiem dlaczego ten sigsegv jest.

--- edit ---
Poprawa błędu w kodzie.

--- edit 2 ---
dodanie var w konstruktorze wątku
poprawa błędu w kodzie.

1

Na pierwszy rzut oka w przypadku tablicy z nieparzystą ilością elementów tablice nie będą równe a u Ciebie tak:

SetLength(Matrix[i], Length(AMatrix) div 2);

więc dalej się wywali

if AMatrix[i] < Highest div 2 then...else...

dodanie znaczników <code class="delphi"> - furious programming

0

Create(var AMatrix : array of Integer);
W innym wypadku możesz mieć stłuczkę ze zliczaniem referencji i zbyt wczesnym zwalnianiem danych.

0

@faber Wiem o tym i nad tym popracuję jak tworzenie wątków i sortowanie tablic o parzystej ilości elementów będzie działać bo to jest w sumie kosmetyka.
A co do drugiego warunku to dzieli on elementy zapisane w tablicy do sortowania na dwie tablice po każdej na wątek przy założeniu, że jedna tablica zawiera elementy od najmniejszego do połowy wartości największego a druga zawiera od połowy wartości największego do największego. Tutaj błędu nie widzę.

@Patryk27 to poprawiłem zanim odpisałeś jednak sigsegv dalej wyskakuje.

Ah i zmieniłem jedną rzecz:
w konstruktorze dałem CreateSuspended na true i w procedurze sort dodałem takie coś:

  Sort[0].Start;
  Sort[1].Start;

  for i := 0 to 1 do
    if not Sort[i].Terminated then sleep(2);

  for i := 0 to 1 do
    FreeAndNil(Sort[i]);

I teraz zaczęło SIGSEGV wywalać w warunku if not Sort[i].Terminated then sleep(2); przy odczycie terminated. Wcześniej wywalało na Create.

2
procedure BubbleSort(var AMatrix : array of Integer; ACompFunc : TCompFunc);
var
  i,j : Word;
begin
  for i := Low(AMatrix) to High(AMatrix) do
    for j := Low(AMatrix) to High(AMatrix) do
    begin
      if ACompFunc(AMatrix[j], AMatrix[j+1]) then // j+1 - poza zakresem tablicy
        Swap(AMatrix[j], AMatrix[j+1]); // j+1 - poza zakresem tablicy
    end;
end;
 for i := 0 to 1 do
    while not Sort[i].Terminated do sleep(2);
0

Banalny błąd. Dzięki za zwrócenie uwagi. poprawiłem jednak dalej nie rozwiązuje to sigsegv.

edit do edit up
To dziwne bo mimo przekroczenia zakresu jak używam tego do sortowania to normalnie działa i nie sypie błędami. Ale poprawię bo może w wątku głównym nie sypie a w wątkach pobocznych powstaje ten sigsegv.

edit do mój edit

procedure BubbleSort(var AMatrix : array of Integer; ACompFunc : TCompFunc);
var
  i,j : Word;
begin
  for i := Low(AMatrix) to High(AMatrix) - 1 do
    for j := Low(AMatrix) to High(AMatrix) - 1 do
    begin
      if ACompFunc(AMatrix[j], AMatrix[j+1]) then
        Swap(AMatrix[j], AMatrix[j+1]);
    end;
end;   

sigsegv dalej wypada :/

0

Spróbuj jeszcze zamienić:

Matrix  : array[0..1] of array of Integer;

na:

Matrix  : array[0..1] of  TData;

Miałem kiedyś podobne jazdy ale jeszcze na Delphi3 lub Delphi4.

Oraz zmień nazwę globalnej zmiennej:

 Matrix : array[0..9,0..Max] of integer;
0

Nie pomogło :/

Zmieniłem nazwę "Max" na "Zakres" (wiem wiem nie powinno się używaź polskich nazw) i zamieniłem to array of... na TData. Ale sigsegv dalej wypada.

Nie mam pojęcia co schrzaniłem...

0

No to wklej całość po poprawkach których było sporo.

0

Następny:

  for i := 0 to 2 do
    for j := Low(Matrix[i]) to High(Matrix[i]) do
    begin
      AMatrix[k] := Matrix[i,j];
      Inc(k);
    end; 

od 0 do 1 powinno być.

dodanie znacznika <code class="delphi"> - furious programming

babubabu napisał(a):

@faber Wiem o tym i nad tym popracuję jak tworzenie wątków i sortowanie tablic o parzystej ilości elementów będzie działać bo to jest w sumie kosmetyka.

BTW , przykład robi na nieparzystej ilości. Od 0 do 1000 czyli 1001

0

Kod po poprawkach:

unit BSort;

{==============================================================================}

{$mode objfpc}{$H+}

{==============================================================================}

interface

{==============================================================================}

uses
  Classes, SysUtils;

{==============================================================================}

type
  TcompFunc = function(AValue1, AValue2 : Integer) : boolean;

{==============================================================================}

procedure BubbleSort(var AMatrix : array of Integer; ACompFunc : TCompFunc);
function V1LargerV2(AValue1, AValue2 : Integer) : Boolean;

{==============================================================================}

implementation

{==============================================================================}

procedure Swap(var AValue1, AValue2 : Integer);
var
  Tmp : Integer;
begin
  Tmp := AValue1;
  AValue1 := AValue2;
  AValue2 := Tmp;
end;

{==============================================================================}

function V1LargerV2(AValue1, AValue2 : Integer) : Boolean;
begin
  result := AValue1 > AValue2;
end;

{------------------------------------------------------------------------------}

procedure BubbleSort(var AMatrix : array of Integer; ACompFunc : TCompFunc);
var
  i,j : Word;
begin
  for i := Low(AMatrix) to High(AMatrix) - 1 do
    for j := Low(AMatrix) to High(AMatrix) - 1 do
    begin
      if ACompFunc(AMatrix[j], AMatrix[j+1]) then
        Swap(AMatrix[j], AMatrix[j+1]);
    end;
end;

{==============================================================================}

end.
unit MultiThreadSort;

{==============================================================================}

{$mode objfpc}{$H+}

{==============================================================================}

interface

{==============================================================================}

uses
  Classes, SysUtils, BSort;

{==============================================================================}

type
  TData = array of integer;
  PData = ^TData;

{------------------------------------------------------------------------------}

type
  TSort = class(TThread)
      FMatrix : PData;
    protected
      procedure Execute; override;
    public
      constructor Create(var AMatrix : array of Integer);
    public
      property Terminated;
  end;

{==============================================================================}

implementation

{==============================================================================}

constructor TSort.Create(var AMatrix : array of Integer);
begin
  inherited Create(true);
  FreeOnTerminate := False;
  FMatrix := @AMatrix;
end;

{------------------------------------------------------------------------------}

procedure TSort.Execute;
begin
  BubbleSort(FMatrix^, @V1LargerV2);
end;

{==============================================================================}

end.
program sortuj;

{==============================================================================}

{$mode objfpc}{$H+}

{==============================================================================}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes, SysUtils, MultiThreadSort, BSort, Crt;

{==============================================================================}

const
  Zakres = 1001;

{==============================================================================}

var
  Start  : Double;
  Stop   : Double;
  Time   : array[0..1] of Double;
  Matrix : array[0..9,0..Zakres] of integer;
  i,j    : Word;

{==============================================================================}

procedure Sort(var AMatrix : array of Integer);
var
  Sort    : array[0..1] of TSort;
  Matrix  : array[0..1] of TData;
  Highest : Integer;
  i, j, k : Word;
begin
  Highest := Low(Integer);
  for i := Low(AMatrix) to High(AMatrix) do
    if AMatrix[i] > Highest then
      Highest := AMatrix[i];

  for i := 0 to 1 do
    SetLength(Matrix[i], Length(AMatrix) div 2);

  j := 0;
  k := 0;
  for i := Low(AMatrix) to High(AMatrix) do
    if AMatrix[i] < Highest div 2 then
    begin
      Matrix[0,j] := AMatrix[i];
      Inc(j);
    end
    else
    begin
      Matrix[1,k] := AMatrix[i];
      Inc(k);
    end;

  for i := 0 to 1 do
    Sort[i] := TSort.Create(Matrix[i]);

  Sort[0].Start;
  Sort[1].Start;

  for i := 0 to 1 do
    while not Sort[i].Terminated do sleep(2);

  for i := 0 to 1 do
    FreeAndNil(Sort[i]);

  k := 0;
  for i := 0 to 1 do
    for j := Low(Matrix[i]) to High(Matrix[i]) do
    begin
      AMatrix[k] := Matrix[i,j];
      Inc(k);
    end;
end;

{==============================================================================}

begin
  Randomize;
  ClrScr;

  for i := 0 to 9 do
  begin
    Write('Losowanie ', i, ' tablicy...');
    for j := 0 to Zakres do
      Matrix[i,j] := Random(60000) - 30000;
    Writeln('Wylosowana');
  end;

  Writeln;
  Start := TimeStampToMsecs(DateTimeToTimeStamp(Now));
  for i := 0 to 9 do
  begin
    Write('Sortowanie ', i, ' tablicy...');
    BubbleSort(Matrix[i],@V1LargerV2);
    Writeln('Posortowana');
  end;
  Stop := TimeStampToMsecs(DateTimeToTimeStamp(Now));
  Time[0] := Stop - Start;

  Writeln;
  for i := 0 to 9 do
  begin
    Write('Losowanie ',i,' tablicy...');
    for j := 0 to Zakres do
      Matrix[i,j] := Random(60000) - 30000;
    Writeln('Wylosowana');
  end;

  Writeln;
  Start := TimeStampToMsecs(DateTimeToTimeStamp(Now));
  for i := 0 to 9 do
  begin
    Write('Sortowanie dwuwątkowe', i, ' tablicy...');
    Sort(Matrix[i]);
    Writeln('Posortowana');
  end;
  Stop := TimeStampToMsecs(DateTimeToTimeStamp(Now));
  Time[1] := Stop - Start;

  Writeln;
  Writeln('Sortowanie bąbelkowe : ',Time[0]);
  Writeln('Sortowanie dwuwątkowe: ',Time[1]);
  Readln;
end.
0

Zrób z Matrix tablicę klas, albo operuj na wskaźnikach na liczbę (PInteger czy co tam masz w kodzie), inaczej to się nie sprawdzi :P
Ewentualnie niech Matrix będzie tablicą wskaźników na tablice.

0

Borze zielony... Zrobię z Matrix tablicę wskaźników na tablicę wskaźników na wskaźniki na integery obudowane w klasy i powinno być git.

A tak na poważnie prościej się nie da?

0

Ale co jest trudnego w tablicy wskaźników? :|

Type PFoo = ^TFoo;
     TFoo = Array[0..Zakres] of Integer;

Type TBar = Array[0..9] of PFoo;

Tyle i wsio. Możesz także kombinować dalej albo napisać własny kompilator.

0

No nie chodzi że to trudne tylko dużo dłubania :P No coś sobie podłubię :)

0

Kompilator powinien drzeć się wniebogłosy - niekompatybilność typów:

Matrix : array[0..9,0..Zakres] of integer;
procedure BubbleSort(var AMatrix : array of Integer; ACompFunc : TCompFunc);
BubbleSort(Matrix[i],@V1LargerV2);
0

No to widocznie dla fpc zapis

Matrix : array[0..9,0..Zakres] of integer;

jest wymienny z zapisem

Matrix : array[0..9] of array[0..Zakres] of integer; 
0

Skoro mowa o zapisie - oczywiście zdajesz sobie sprawę, że:

BubbleSort(var AMatrix : array of Integer;

Nie jest tym samym, co:

BubbleSort(var AMatrix: TArrayOfInteger);

Tak? :P

Swoją drogą: http://ideone.com/z0ldpQ

0

Owszem i nie tylko fpc.
Ale array[0..Zakres] of integer; nie jest wymienny z procedure BubbleSort(var AMatrix : array of Integer; ...

0

O.o To czemu to działa. Przynajmniej w wątku głównym.

Zmieniłem kod:

Matrix : array[0..9] of array of integer;

i gdzieś po drodze dodałem

 for i := 0 to 9 do
  begin
    SetLength(Matrix[i],Zakres); 
/...

Sigsegv dalej wywala.

0

Przypadkiem.
http://ideone.com/z0ldpQ

0

Można użyć Slice - aby to obejść.

0

No dobra działa przypadkiem a sigsegv występuje przy próbie odczytu property Terminated. Czemu? Przez to, że przypadkiem działa i jednak nie działa czy coś innego jest nie tak?

0

Bo mażesz po nieswojej pamięci, no dunno. Korzystasz z UB, wszystko się może stać.

0

Błąd kompilatora - nie powinien tego przepuścić, użyj Slice

0

Dobra bo już się pogubiłem. Użyję standardowej metody poprawy kodu jak się pogubię ctrl+a -> delete. I napiszę jeszcze raz.

0

Próba numer dwa po uwzględnieniu waszych sugestii wygląda tak

Unit BSort:

unit BSort;

{==============================================================================}

{$mode objfpc}{$H+}

{==============================================================================}

interface

{==============================================================================}

uses
  Classes, SysUtils;

{==============================================================================}

type
  TcompFunc = function(AValue1, AValue2 : Integer) : boolean;
  TIntegerArray = array of integer;
  PIntegerArray = ^TIntegerArray;

{==============================================================================}

procedure BubbleSort(var AMatrix : TIntegerArray; ACompFunc : TCompFunc);
function V1LargerV2(AValue1, AValue2 : Integer) : Boolean;

{==============================================================================}

implementation

{==============================================================================}

procedure Swap(var AValue1, AValue2 : Integer);
var
  Tmp : Integer;
begin
  Tmp := AValue1;
  AValue1 := AValue2;
  AValue2 := Tmp;
end;

{==============================================================================}

function V1LargerV2(AValue1, AValue2 : Integer) : Boolean;
begin
  result := AValue1 > AValue2;
end;

{------------------------------------------------------------------------------}

procedure BubbleSort(var AMatrix : TIntegerArray; ACompFunc : TCompFunc);
var
  i,j : Word;
begin
  for i := Low(AMatrix) to High(AMatrix) - 1 do
    for j := Low(AMatrix) to High(AMatrix) - 1 do
    begin
      if ACompFunc(AMatrix[j], AMatrix[j+1]) then
        Swap(AMatrix[j], AMatrix[j+1]);
    end;
end;

{==============================================================================}

end.

Unit MultiThreadSort:

unit MultiThreadSort;

{==============================================================================}

{$mode objfpc}{$H+}

{==============================================================================}

interface

{==============================================================================}

uses
  Classes, SysUtils, BSort;

{==============================================================================}

type
  TSort = class(TThread)
      FMatrix : PIntegerArray;
    protected
      procedure Execute; override;
    public
      constructor Create(var AMatrix : TIntegerArray);
    public
      property Terminated;
  end;

{==============================================================================}

implementation

{==============================================================================}

constructor TSort.Create(var AMatrix : TIntegerArray);
begin
  inherited Create(False);
  FreeOnTerminate := False;
  FMatrix := @AMatrix;
end;

{------------------------------------------------------------------------------}

procedure TSort.Execute;
begin
  BubbleSort(FMatrix^, @V1LargerV2);
end;

{==============================================================================}

end.

Program:

program sortuj;

{==============================================================================}

{$mode objfpc}{$H+}

{==============================================================================}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes, SysUtils, MultiThreadSort, BSort, Crt;

{==============================================================================}

const
  Zakres = 20;

{==============================================================================}

var
  Start  : Double;
  Stop   : Double;
  Time   : array[0..1] of Double;
  Matrix : array[0..9] of TIntegerArray;
  i,j    : Word;

{==============================================================================}

procedure Sort(var AMatrix : TIntegerArray);
var
  Sort    : array[0..1] of TSort;
  Matrix  : array[0..1] of TIntegerArray;
  Highest : Integer;
  i, j, k : Word;
begin
  Highest := Low(Integer);
  for i := Low(AMatrix) to High(AMatrix) do
    if AMatrix[i] > Highest then
      Highest := AMatrix[i];

  for i := 0 to 1 do
    SetLength(Matrix[i], 0);

  j := 0;
  k := 0;
  for i := Low(AMatrix) to High(AMatrix) do
    if AMatrix[i] < Highest div 2 then
    begin
      SetLength(Matrix[0], Length(Matrix[0]) + 1);
      Matrix[0,j] := AMatrix[i];
      Inc(j);
    end
    else
    begin
      SetLength(Matrix[1], Length(Matrix[1]) + 1);
      Matrix[1,k] := AMatrix[i];
      Inc(k);
    end;

  for i := 0 to 1 do
    Sort[i] := TSort.Create(Matrix[i]);

  for i := 0 to 1 do
    while not Sort[i].Terminated do
      sleep(1);

  for i := 0 to 1 do
    FreeAndNil(Sort[i]);

  k := 0;
  for i := 0 to 1 do
    for j := Low(Matrix[i]) to High(Matrix[i]) do
    begin
      AMatrix[k] := Matrix[i,j];
      Inc(k);
    end;
end;

{==============================================================================}

begin
  Randomize;
  ClrScr;

  for i := 0 to 9 do
  begin
    SetLength(Matrix[i],Zakres);
    Write('Losowanie ', i, ' tablicy...');
    for j := 0 to Zakres - 1 do
      Matrix[i,j] := Random(100) - 50;
    Writeln('Wylosowana');
  end;

  Writeln;
  Start := TimeStampToMsecs(DateTimeToTimeStamp(Now));
  for i := 0 to 9 do
  begin
    Write('Sortowanie ', i, ' tablicy...');
    BubbleSort(Matrix[i],@V1LargerV2);
    Writeln('Posortowana');
  end;
  Stop := TimeStampToMsecs(DateTimeToTimeStamp(Now));
  Time[0] := Stop - Start;

  Writeln;
  for i := 0 to 9 do
  begin
    Write('Losowanie ',i,' tablicy...');
    for j := 0 to Zakres do
      Matrix[i,j] := Random(100) - 50;
    Writeln('Wylosowana');
  end;

  Writeln;
  Start := TimeStampToMsecs(DateTimeToTimeStamp(Now));
  for i := 0 to 9 do
  begin
    Write('Sortowanie dwuwatkowe ', i, ' tablicy...');
    Sort(Matrix[i]);
    Writeln('Posortowana');
  end;
  Stop := TimeStampToMsecs(DateTimeToTimeStamp(Now));
  Time[1] := Stop - Start;

  Writeln;
  Writeln('Sortowanie bąbelkowe : ',Time[0]);
  Writeln('Sortowanie dwuwatkowe: ',Time[1]);
  Readln;
end.

Zmieniłem podział na dwie tablice bo poprzedni był błędny (ten trzeba zabezpieczyć przed pustą i jednoelementową tablicą) i zrobiłem specjalny typ TIntegerArray : array of Integer;

W prawdzie przestało rzucać sigsev ale zawiesza się na probie odczytu Terminated wątków.

Ktoś wie czemu i jak to naprawić?

Ps. Moim skromnym zdaniem spoilery by się przydały.

0
BubbleSort(FMatrix^, @V1LargerV2);

Stawiam na to, że dereferencją tworzysz kopię.

Btw, zmienne typu word wcale nie przyśpieszają działania kodu, a wręcz przeciwnie (w przypadku x86 i x86-64) :P

0

A dlaczego w klasie deklarujesz te terminated?

0

@furious programming Nie wiedziałem dzięki :)
@Patryk27 nawet jeśli tworzę kopię to wątek powinien posortować kopię i zakończyć działanie. A jak sobie ustawiłem breakpoint w sortowaniu to w wątku śmiga do jakiegoś momentu a następnie zwiecha. Nie mam pojęcia co robię nie tak. Nawet zacząłem analizować ten przykład http://wiki.lazarus.freepascal.org/Example_of_multi-threaded_application:_array_of_threads ale nie mogę wymyślić co jest nie tak.

1 użytkowników online, w tym zalogowanych: 0, gości: 1