Max concurrent thread count limited to 383 on Linux
Original Reporter info from Mantis: zakiwi
-
Reporter name: Erich Kuba
Original Reporter info from Mantis: zakiwi
- Reporter name: Erich Kuba
Description:
Hi there,
I've hit a limit of 383 concurrent threads in an application that we are developing. This is a consistent limit, and can be reproduced through a simple program.
The purpose of the sample program is to emmulate 500 concurrent threads. Ideally we would like to get to several thousand.
Please let me know if this is a bug or something that I can control.
The error message that I get when we exceed 382 threads is: EThread: Failed to create new thread
Here is a sample program based on another sample that I found on this site:
program test_thread;
{$mode objfpc}{$H+}
{$define usecthreads}
uses
{$IFDEF FPC}
cthreads,
{$ENDIF}
SysUtils,
Classes;
type
TTestThread = class(TThread)
private
protected
procedure Execute; override;
end;
const
MAX_THREAD : integer = 1000;
var
I : integer;
{ TTestThread }
procedure TTestThread.Execute;
begin
Writeln('[' + IntToStr(Self.ThreadID) + '] Running...');
Sleep(10000);
Writeln('[' + IntToStr(Self.ThreadID) + '] Done...');
Terminate;
end;
procedure CreateThread;
var
TestThread : TTestThread;
begin
TestThread := TTestThread.Create(true);
TestThread.FreeOnTerminate := True;
TestThread.Resume;
end;
begin
Sleep(1000);
try
for I := 1 to MAX_THREAD do
begin
Writeln('Create ' + IntToStr(I) + ' ...');
CreateThread;
Sleep(20);
end;
Writeln('Finish');
ReadLn;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
Kind regards
Erich
Mantis conversion info:
- Mantis ID: 13105
- Version: 2.2.2