Recent

Author Topic: Thread Creation Error(?)  (Read 2053 times)

codeman

  • Jr. Member
  • **
  • Posts: 78
Thread Creation Error(?)
« on: October 19, 2014, 08:21:12 pm »
I get an error on Thread creation while my app is running..
basicly i create the thread on Form.OnCreate  and after termination

Code: [Select]
Thread.Execute
(
freeonterminate:=true
process();
MyThread.Terminate;
MyThread.WaitFor;
)
i recreate the thread every 20-30s
it runs fine but after 15-20min i get a msg box error which says
Code: [Select]
"Thread creation error : the available saving space is not enough to execute this command..
 probably it means this one
"MyThread:=TMyThread.Create(false); "

Press OK to ignore and risk data corruption
Press cancel to kill the program.


I check if thread is terminated and when is terminated after some time i recreate a new thread like this
Code: [Select]
Procedure StartThread();
begin
    MyThread:=TMyThread.Create(false);
    if (Assigned(MyThread.FatalException)) then
    begin
        ....
    end;
end;
« Last Edit: October 19, 2014, 08:47:38 pm by codeman »
Lazarus v2.02 Win10

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Thread Creation Error(?)
« Reply #1 on: October 20, 2014, 04:48:02 am »
There's a mistake here at least:
Code: [Select]
Thread.Execute
(
freeonterminate:=true
process();
MyThread.Terminate;
MyThread.WaitFor;
)
You can't call WaitFor from inside Execute, the whole functions purpose is to wait until Execute ends, therefore it's infinite loop. Remove both these lines and it should be fine for that part
Code: [Select]
MyThread.Terminate;
MyThread.WaitFor;
(referring to self object using reference variable (MyThread) is also unnecessary and potentially dangerous)

 

TinyPortal © 2005-2018