Recent

Author Topic: error creating thread.  (Read 912 times)

liewald

  • Full Member
  • ***
  • Posts: 142
error creating thread.
« on: February 01, 2023, 10:44:20 am »
OS Opensuse 15.4, Lazarus version 2.3.0, FPC ver 3.2.2


I'm having problems creating threads and getting this error

"Project SR raised exception class 'External: SIGSEGV'.

 At address 4482BC"

the program has been successfully running for the past 3-4 years but I had to upgrade the machine due to support for the OS (OS 15.1) being discontinued. On recompiling the program the program crashes on the thread creation call. there's nothing special in the thread constructor and the original code that worked hasn't changed.

here's the constructor that fails :

constructor TScriptThread.Create(processorid:integer;script:string;CreateSuspended:boolean);
  begin
    scriptprocessor := processorID;
    Scriptname := script;
    FreeOnTerminate := True;
   inherited Create(CreateSuspended);
end;

Any ideas anyone?

Dave

alpine

  • Hero Member
  • *****
  • Posts: 1064
Re: error creating thread.
« Reply #1 on: February 01, 2023, 11:35:08 am »
You should provide more information about.

How it was constructed (source) at the first place? 
What are scriptprocessor and Scriptname ? Fields? Simple properties or they have setters? inherited Create was called last - is TScriptThread a direct descendant of TThread?
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

liewald

  • Full Member
  • ***
  • Posts: 142
Re: error creating thread.
« Reply #2 on: February 01, 2023, 12:13:30 pm »
I may have mentioned this has actually been working for 3-4 years prior to the system rebuild without an issue but to answer your queries:

scriptprocessor is an integer to keep track of the cpu that the thread is attached to in the control array
scriptname  is a string holding the executable in this case a batch file

tscriptthread is a tthread descendant

 TScriptThread = class(TThread)
    private
    scriptprocessor:integer;
    scriptname:string;
    fStatusText : string;
    scriptstart: boolean;
    procedure ShowStatus;
    protected
      procedure Execute override;
    public
      Constructor Create(processorID:integer;script:string;Createsuspended:boolean);
    end;       

the crash is immediately on the create call

Dave

tetrastes

  • Sr. Member
  • ****
  • Posts: 481
Re: error creating thread.
« Reply #3 on: February 01, 2023, 12:20:34 pm »
Check if uses cthreads in .lpr lost somehow.

liewald

  • Full Member
  • ***
  • Posts: 142
Re: error creating thread.
« Reply #4 on: February 01, 2023, 12:27:47 pm »
yup uses cthreads, cmem and heaptrace

alpine

  • Hero Member
  • *****
  • Posts: 1064
Re: error creating thread.
« Reply #5 on: February 01, 2023, 12:33:03 pm »
I may have mentioned this has actually been working for 3-4 years prior to the system rebuild without an issue but to answer your queries:
*snip*
You didn't provide the source line where the constructor was invoked.
Is it looks as a trivial instance construction, e.g.
Code: Pascal  [Select][+][-]
  1.   T := TScriptThread.Create(id, script, susp);
Or it is something different?

I don't see other reason for SIGSEGV except a bad Self pointer at this point.
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

liewald

  • Full Member
  • ***
  • Posts: 142
Re: error creating thread.
« Reply #6 on: February 01, 2023, 12:36:40 pm »
OK it's invoked in an array of tscriptthread like this

 processarray := tscriptthread.Create(i,scommand,false); 

but the same error happened when I used a simple call

testthread := tscriptthread.Create(i,scommand,false); 


liewald

  • Full Member
  • ***
  • Posts: 142
Re: error creating thread.
« Reply #7 on: February 01, 2023, 12:38:12 pm »
the full thing looks like this

procedure tsrmain.launchprocess(i:integer) ;

  var scriptname : string;
      scommand,sresult : ansistring;
      res : boolean;
      scriptprocess : tasyncprocess;

begin
  if nextpointer < scriptlist.count then
  begin
  scriptname := scriptlist.items[nextpointer];
  scommand := scriptdirectory.Directory + '/' + scriptname;
  try
  processarray := tscriptthread.Create(i,scommand,false);
  if assigned(processarray.fatalexception) then
  raise processarray.fatalexception;
  nextpointer := nextpointer + 1;
 //  testthread := tscriptthread.Create(i,scommand,false);
 except
  On E: Exception do
  srmain.Memo1.lines.Append('Thread Failure');
  end;
  end;   

alpine

  • Hero Member
  • *****
  • Posts: 1064
Re: error creating thread.
« Reply #8 on: February 01, 2023, 12:43:39 pm »
Could you please put the source into code tags, otherwise the array subscriptions are lost and everything is italicized.
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

Zvoni

  • Hero Member
  • *****
  • Posts: 2327
Re: error creating thread.
« Reply #9 on: February 01, 2023, 12:47:22 pm »
yup uses cthreads, cmem and heaptrace
OUCH!!
Never ever add HeapTrc to uses-clause! --> https://wiki.freepascal.org/heaptrc

and there is also some issue with using heaptrc and cmem at the same time, since heaptrc has/it's its own memory-manager, but for the life of me i can't find the Wiki-Entry
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

liewald

  • Full Member
  • ***
  • Posts: 142
Re: error creating thread.
« Reply #10 on: February 01, 2023, 12:51:35 pm »
Yup that was the culprit, removes heaptrace and is revived..

Funny how it was never a problem before!!!!

thanks

TRon

  • Hero Member
  • *****
  • Posts: 2515
Re: error creating thread.
« Reply #11 on: February 01, 2023, 12:53:39 pm »
Yup that was the culprit, removes heaptrace and is revived..

Funny how it was never a problem before!!!!
That is because over the years the functionality of heaptrace changed. It used to be possible (actually required) to include unit heaptrace but that changed.

Hence why user Zvoni tried to locate that specific entry in the wiki.

At least it is documented: https://www.freepascal.org/docs-html/rtl/heaptrc/usage.html
Quote
You must use the -gh switch, to let the compiler insert the unit by itself, so you don't have to include it in your uses clause. In fact, as of version 3.0.0 you may no longer do so.
« Last Edit: February 01, 2023, 12:57:58 pm by TRon »

liewald

  • Full Member
  • ***
  • Posts: 142
Re: error creating thread.
« Reply #12 on: February 01, 2023, 01:01:24 pm »
Thanks All

Back to genetics and brain imaging now  :D

Dave

Zvoni

  • Hero Member
  • *****
  • Posts: 2327
Re: error creating thread.
« Reply #13 on: February 01, 2023, 01:28:22 pm »
Hence why user Zvoni tried to locate that specific entry in the wiki.
I actually found it on the Wiki-Page i linked above: https://wiki.freepascal.org/heaptrc#Why_heaptrc_should_not_be_added_to_the_uses_clause_manually
It's in the fine-print on the bottom of the example (reminds me of contracts....duf! :))
Quote
Note: If your program is designed to use an alternative memory manager, you can adapt your program's uses clause like so:
... code follows.....
In the above example the conditional in the uses clause makes sure that the CMem memory manager is only compiled in if the Heaptrc option is not used.
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: error creating thread.
« Reply #14 on: February 01, 2023, 01:59:18 pm »
Since I wrote most of that wiki entry based on direct contact with Florian (as per bug reports) I reviewed it and removed a bogus entry.
heaptrc is a memory manager. Mixing memory memory managers is not a good idea.
Mixing heaptrc with any other memory manager is plain wrong.
If you have any comments on how I described this in the wiki, plz consult me or if you are concerned , one of the dev team before adding nonsense. Nonsense removed.

Wiki should now be in a proper state.
Any criticism is welcome.
« Last Edit: February 01, 2023, 02:09:20 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

 

TinyPortal © 2005-2018