View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0009016FPCCompilerpublic2007-06-06 12:332007-09-25 12:56
ReporterLionel 
Assigned ToJonas Maebe 
PrioritynormalSeverityblockReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version2.3.1Product Build 
Target VersionFixed in Version2.2.2 
Summary0009016: Create Thread Limit
DescriptionHello, there is thread creation limit on linux, i don't try under win32 environment.
With Kylix compiler, no problem.
Additional InformationVery simple sample :

program test_thread;

{$IFDEF FPC}
{$PACKRECORDS C}
{$MODE DELPHI} // Delphi-compatible mode in FreePascal
{$ASMMODE Intel}
{$UNDEF BORLAND}
{$ELSE}
{$APPTYPE CONSOLE}
{$ENDIF}

uses
{$IFDEF FPC}
  cthreads,
{$ENDIF}
  SysUtils,
  Classes;

type
  TTestThread = class(TThread)
  private
    { DĂ©clarations privĂ©es }
  protected
    procedure Execute; override;
  end;

const
  MAX_THREAD : integer = 1000;
var
  I : integer;


{ TTestThread }

procedure TTestThread.Execute;
begin
  Writeln('[' + IntToStr(Self.ThreadID) + '] Running...');
  Terminate;
end;

procedure CreateThread;
var
  TestThread : TTestThread;
begin
  TestThread := TTestThread.Create(true);
  TestThread.FreeOnTerminate := true;
  TestThread.Resume;
end;

begin
  try
    for I := 1 to MAX_THREAD do
      begin
        Writeln('Create ' + IntToStr(I) + ' ...');
        CreateThread;
        Sleep(100);
      end;
    Writeln('Finish');
    ReadLn;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.
TagsNo tags attached.
FPCOldBugId0
Fixed in Revision8430
Attached Files? file icon test_thread [^] (420,296 bytes) 2007-06-06 14:24

- Relationships
has duplicate 0009322closedJonas Maebe With FPC 2.1.5 threads are not freed/reused properly 
has duplicate 0010815closedJonas Maebe EThread, Failed to create new threads. 

-  Notes
(0012986)
Marco van de Voort (manager)
2007-06-06 13:25
edited on: 2007-06-06 13:26

I can't test with Kylix, but this sounds awfully like a process limitation.

Try to see if it depends on ulimit settings.

It could be that Kylix doesn't have this limit because the older thread libs that it uses don't implement the limit checking (I assume the remark about Kylix is on exactly the same machine + account)

(0012987)
Lionel (reporter)
2007-06-06 14:24

Yes, it's on same machine.
I build the project with :
fpc -Mdelphi test_thread.dpr

and the limite is here :
vvvvvvvvvvvvvvvvvvvvvvvv
........................
Create 380 ...
[-1099203680] Running...
Create 381 ...
[-1090810976] Running...
Create 382 ...
[-1082418272] Running...
Create 383 ...
EThread: Failed to create new thread
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The number of thread is always 383, I have tried the same application on other machine and this the same problem.

I've joined compiled application.
(0012988)
Lionel (reporter)
2007-06-06 14:29

#ulimit - a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
pending signals (-i) 16382
max locked memory (kbytes, -l) 32
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) unlimited
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
(0012989)
Jonas Maebe (manager)
2007-06-06 15:26
edited on: 2007-06-06 15:27

The problem is improper reaping of dead threads under certain circumstances. The error you see is caused by running out of virtual address space, because it's entirely consumed by the stacks allocated for threads which are finished running, but still lingering around.

(0012990)
Lionel (reporter)
2007-06-06 15:37

There is a solution to release the thread completely and free virtual adress for another thread ? It's a bug from linux or fpc ?
I don't have fpc installed on win32 and I cannot test this.

I cannot migrate my application from delphi if the threads are limited at 383.

Thank you for your reactvity
(0012991)
Jonas Maebe (manager)
2007-06-06 16:10

It's an FPC bug.

- Issue History
Date Modified Username Field Change
2007-06-06 12:33 Lionel New Issue
2007-06-06 13:25 Marco van de Voort Note Added: 0012986
2007-06-06 13:26 Marco van de Voort Note Edited: 0012986
2007-06-06 14:24 Lionel Note Added: 0012987
2007-06-06 14:24 Lionel File Added: test_thread
2007-06-06 14:29 Lionel Note Added: 0012988
2007-06-06 15:26 Jonas Maebe Note Added: 0012989
2007-06-06 15:27 Jonas Maebe Note Edited: 0012989
2007-06-06 15:37 Lionel Note Added: 0012990
2007-06-06 16:10 Jonas Maebe Note Added: 0012991
2007-06-06 17:19 Jonas Maebe Fixed in Revision => 7588
2007-06-06 17:19 Jonas Maebe Status new => resolved
2007-06-06 17:19 Jonas Maebe Fixed in Version => 2.3.1
2007-06-06 17:19 Jonas Maebe Resolution open => fixed
2007-06-06 17:19 Jonas Maebe Assigned To => Jonas Maebe
2007-07-24 18:11 Jonas Maebe Relationship added has duplicate 0009322
2007-07-29 16:56 Florian Status resolved => closed
2007-09-25 12:56 Jonas Maebe FPCOldBugId => 0
2007-09-25 12:56 Jonas Maebe FPCTarget => -
2007-09-25 12:56 Jonas Maebe Fixed in Revision 7588 => 8430
2007-09-25 12:56 Jonas Maebe Fixed in Version 2.3.1 => 2.2.1
2008-02-12 13:19 Jonas Maebe Relationship added has duplicate 0010815



MantisBT 1.2.12[^]
Copyright © 2000 - 2012 MantisBT Group
Powered by Mantis Bugtracker