Recent

Author Topic: [SOLVED] Error class 'external : SIGSEGV' when running Thread  (Read 1183 times)

incendio

  • Jr. Member
  • **
  • Posts: 90
Re: [SOLVED] Error class 'external : SIGSEGV' when running Thread
« Reply #30 on: June 18, 2019, 12:15:15 pm »
Hi guys,

Just wondering about Thread Create.
For example, I have these codes
Code: Pascal  [Select]
  1. constructor TD3GetDtThr.Create(CreateSuspended: boolean; AThreadDone: TNotifyEvent);
  2. begin
  3.   inherited Create(true);
  4.   FreeOnTerminate := true;
  5.   OnTerminate := AThreadDone;
  6.   Start;
  7. end;
  8.  
  9. // thread declaration
  10. Dt3 := TD3GetDtThr.Create( True,@ThreadDone);
  11. Dt3.Id1 := 1;
  12. Dt3.Id2 := 100;
  13.  

Even though thread Variables Id1 & Id2 declared after thread start, these variable still would be recognized by procedure TD3GetDtThr.Execute. How come?

rvk

  • Hero Member
  • *****
  • Posts: 3745
Re: [SOLVED] Error class 'external : SIGSEGV' when running Thread
« Reply #31 on: June 18, 2019, 12:19:20 pm »
Even though thread Variables Id1 & Id2 declared after thread start, these variable still would be recognized by procedure TD3GetDtThr.Execute. How come?
You can't be certain of that.
Maybe the TThread.Execute is already started, maybe not.
But I wouldn't count on it.

Try to put a sleep(1000) after the TD3GetDtThr.Create() and see what happens then.

(Now the Id1 and Id2 are assigned just microseconds after creating the thread and that could be just before the TThread.Execute, but don't count on that.)

incendio

  • Jr. Member
  • **
  • Posts: 90
Re: [SOLVED] Error class 'external : SIGSEGV' when running Thread
« Reply #32 on: June 19, 2019, 04:26:42 am »
To be safe, I removed Start command from constructor, and only call it when all initialization process completed.