Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-05

Problem with threads in Lazarus 0.9.24

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Petr Hložek, OK2CQR

Hello,

my application uses threads.
I have created TStringList for data exchange. It is global variable. If I receive any data from telnet connection I put it into this string list and create thread if is not already created.
Thread read and delete this data from StringList. If I run my program, connect to telnet, it takes about half hour and program crash with this error: Failed to create new thread
I used to Lazarus 0.9.23cvs and I didnt have problem with it. Problem appears after upgrade to 0.9.24 :-(.

Dou you have any idea what can be wrong or what I should do better? Source code of my thread is here:
http://cqrlog.svn.sourceforge.net/viewvc/cqrlog/fDXCluster.pas?view=markup

it start at line nr. 487 and body of the thread begins on line nr. 681.

Thanks for help!

Petr

Reply by email

Lee Jenkins
to Petr Hložek, OK2CQR
Petr Hlo?ek wrote 18 lines
Hello, my application uses threads. I have created TStringList for data exchange. It is global variable. If I receive any data from telnet connection I put it into this string list and create thread if is not already created. Thread read and delete this data from StringList. If I run my program, connect to telnet, it takes about half hour and program crash with this error: Failed to create new thread I used to Lazarus 0.9.23cvs and I didnt have problem with it. Problem appears after upgrade to 0.9.24 :-(. Dou you have any idea what can be wrong or what I should do better? Source code of my thread is here: http://cqrlog.svn.sourceforge.net/viewvc/cqrlog/fDXCluster.pas?view=markup it start at line nr. 487 and body of the thread begins on line nr. 681.

Petr,

I could be wrong, but I think I recall a mail list thread about threads. Below is is a post from a little while ago. Is it related maybe?

Warm Regards, Lee > OK - seems to be an fpc-bug - and the good news: Already fixed in > current 2.2.1. > > In fpc 2.2.0 the TThread.FreeOnTerminate doesn't work as expected > > regards > > Lukas > > Lukas Gradl schrieb: >> > Hello! >> > >> > I have some strange memory problem with a TThread-Descendant. >> > For debugging I created a little test-app with a button on it and the >> > following OnClick-Handler: >> > >> > procedure TForm1.Button1Click(Sender: TObject); >> > begin >> > TThreadDummy.Create; >> > end; >> > >> > The Thread looks like that: >> > >> > type >> > TThreadDummy=class(TThread) >> > protected >> > procedure Execute; override; >> > public >> > constructor Create; >> > end; >> > >> > constructor TThreadDummy.Create; >> > begin >> > inherited create(true); >> > FreeOnTerminate := true; >> > Resume; >> > end; >> > >> > procedure TThreadDummy.Execute; >> > begin >> > //do nothing - just exit! >> > end; >> > >> > The program is compiled using FPC 2.2.0, Lazarus 0.9.24-0 precompiled >> > from Lazarus Page and Debian as OS >> > >> > >> > >> > Every time I press the button, the program uses 8192 Bytes of memory >> > more (according to the ps-command). I've another app with a big TThread >> > descendant, which eats up the same 8192 on every TThreadDescendant.Create... >> > >> > Anyone an idea what I might have done wrong? >> > >> > >> > >> > regards >> > Lukas >> >

Reply by email

Luca Olivetti
to Petr Hložek, OK2CQR: my application uses threads. I have created TStringList for data exchange. It is global…
Show quoted text 11 lines
Hello, my application uses threads. I have created TStringList for data exchange. It is global variable. If I receive any data from telnet connection I put it into this string list and create thread if is not already created. Thread read and delete this data from StringList. If I run my program, connect to telnet, it takes about half hour and program crash with this error: Failed to create new thread I used to Lazarus 0.9.23cvs and I didnt have problem with it. Problem appears after upgrade to 0.9.24 :-(.

I cannot tell if it is the problem, but from a cursory look at the code it seems that you access this stringlist from various threads with no synchronization whatsoever, and this is a no-no, since TStringList isn't threadsafe (or at least I think it isn't, most types, even simple ones, aren't).
You should protect each access to the stringlist with, e.g., a TCriticalSection and be careful to avoid deadlocks.

Bye

Luca

Reply by email

Petr Hložek, OK2CQR
to Lee Jenkins: I could be wrong, but I think I recall a mail list thread about threads. Below is is a…

Hi Lee,

it looks that you are right. I have the same problem. Is there any patch for 2.2.0 version? I tried to download and build older version of fpc (2.0.4) but I cannot compile one of main component for my program.
I tried also latest source code of fpc-2.2.1 but I cannot compile Lazarus 0.9.24 with this version.
Is there any solution or I have to wait for newer Lazarus and fpc?

Thanks for help!

Petr

Lee Jenkins p??e v Ne 18. 05. 2008 v 12:53 -0400:

Show quoted text 25 lines
Petr Hlo?ek wrote: > Hello, > > my application uses threads. > I have created TStringList for data exchange. It is global variable. If > I receive any data from telnet connection I put it into this string list > and create thread if is not already created. > Thread read and delete this data from StringList. If I run my program, > connect to telnet, it takes about half hour and program crash with this > error: Failed to create new thread > I used to Lazarus 0.9.23cvs and I didnt have problem with it. Problem > appears after upgrade to 0.9.24 :-(. > > Dou you have any idea what can be wrong or what I should do better? > Source code of my thread is here: > http://cqrlog.svn.sourceforge.net/viewvc/cqrlog/fDXCluster.pas?view=markup > > it start at line nr. 487 and body of the thread begins on line nr. 681. > Petr, I could be wrong, but I think I recall a mail list thread about threads. Below is is a post from a little while ago. Is it related maybe?

Reply by email

Lee Jenkins
to Petr Hložek, OK2CQR
Petr Hlo?ek wrote 40 lines
Hi Lee, it looks that you are right. I have the same problem. Is there any patch for 2.2.0 version? I tried to download and build older version of fpc (2.0.4) but I cannot compile one of main component for my program. I tried also latest source code of fpc-2.2.1 but I cannot compile Lazarus 0.9.24 with this version. Is there any solution or I have to wait for newer Lazarus and fpc? Thanks for help! Petr Lee Jenkins p??e v Ne 18. 05. 2008 v 12:53 -0400: > Petr Hlo?ek wrote: >> Hello, >> >> my application uses threads. >> I have created TStringList for data exchange. It is global variable. If >> I receive any data from telnet connection I put it into this string list >> and create thread if is not already created. >> Thread read and delete this data from StringList. If I run my program, >> connect to telnet, it takes about half hour and program crash with this >> error: Failed to create new thread >> I used to Lazarus 0.9.23cvs and I didnt have problem with it. Problem >> appears after upgrade to 0.9.24 :-(. >> >> Dou you have any idea what can be wrong or what I should do better? >> Source code of my thread is here: >> http://cqrlog.svn.sourceforge.net/viewvc/cqrlog/fDXCluster.pas?view=markup >> >> it start at line nr. 487 and body of the thread begins on line nr. 681. >> > Petr, > > I could be wrong, but I think I recall a mail list thread about threads. Below > is is a post from a little while ago. Is it related maybe? >

Can you try to grab a snapshot version of lazarus from here? http://www.hu.freepascal.org/lazarus/

The above are pre-compiled binaries.

More information on installing from source can be found here if you're interested in that.
http://wiki.lazarus.freepascal.org/Installing_Lazarus

HIH

Warm Regards, Lee

Reply by email