Forum > General

Threads | file events.c not found | exception class 'External: SIGSEGV'

(1/1)

mvampire:
Dear all.

I'm trying to create array of threads.

To do it, I describe a class:


--- Code: ---Type
    TMyThread = class(TThread)
    private
    protected
      procedure Execute; override;
    public
      start,finish: integer;
      Constructor Create(CreateSuspended : boolean);
    end;

--- End code ---

Each thread should implement simple loop, loop variable goes from 'start' to 'finish'.

So in the main program I'm making the following:


--- Code: ---uses
 cthreads, cmem, pthreads,      //without pthreads debugging is not possible

...
var ThreadsArray: array [1..1500] of TMyThread;
begin
...

for i:=1 to threads do begin
ThreadsArray[i]:=TMyThread.Create(True);
ThreadsArray[i].start:=(i-1)*(Qnum div threads)+1;
ThreadsArray[i].finish:=i*(Qnum div threads);
ThreadsArray[i].Resume;
end;
...

--- End code ---

First thread creates fine, but while creating the second (i=2), I get one of two errors:

1) The file events.c was not found. Do you want to locate it yourself?
or
2)Project raised exception class 'External: SIGSEGV'

Can You help me?
Maybe I'm wrong using array of threads. If yes, how can I create a large number of same threads?

Thank You in advance,

Andrey Sapegin.

runner:
Your code seems ok on the first sight.

What values do the variables have. Maybe you are having "divide by zero" problem or something similar. Also what do you do in the constructor of you thread and in the execute method.

chtreds unit should be the first in the uses of a project (lpr) and not in the unit using threads.

mvampire:

--- Code: ---constructor TMyThread.Create(CreateSuspended : boolean);
  begin
    FreeOnTerminate := True;
    inherited Create(CreateSuspended);
  end;

  procedure TMyThread.Execute;
  var i: integer;
      query1,query2: string;
      AProcess: TProcess;
      AStringList: TStringList;
  begin
i:=start;
    while (not Terminated) and (i<=finish) do begin

query1:=DictArray[Random(n-1)+1];
query2:=DictArray[Random(n-1)+1];
if i mod 100 = 0 then WRITELN(i,' of 10000 done in parallel');

//Solr
AProcess := TProcess.Create(nil);
AStringList := TStringList.Create;
AProcess.CommandLine := '/usr/bin/time -o /data/test_results/time_solr -a php Query_solr_multi.php '+query1+' '+query2;
AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes];
AProcess.Execute;
AStringList.LoadFromStream(AProcess.Output);
//Writeln(response_solr,AStringList.Text);
response_array_solr[i]:=AStringList.Text;
AProcess.Free;
AStringList.Free;

//Sphinx
AProcess.CommandLine := '/usr/bin/time -o /data/test_results/time_sphinx -a php mytest2_php.php -ph -e -l 10 @itemname '+query1+' @description '+query2;
AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes];
AProcess.Execute;
AStringList.LoadFromStream(AProcess.Output);
//Writeln(response_sphinx,AStringList.Text);
response_array_sphinx[i]:=AStringList.Text;
AProcess.Free;
AStringList.Free;

inc(i); if i>finish then Terminate;
      end;
  end;               


--- End code ---

Navigation

[0] Message Index

Go to full version