Thread size defined by code

4

I have a system that at times gets to use more than a thousand concurrent threads and unfortunately needs to run in 32-bit environment .

By default , Delphi allocates 1kb for each new thread , which in a strong> becomes unfeasible for the size of the system in question. I could set a new value via menu, but would lose the option to change it at runtime, if the new size does not meet my demands or is too large for them.

My intention then is to find a form, using the Thread.Execute command to parameterize this size. Be it via ini , BD or whatever, as long as it's in the code.

I know that with the command BeginThread() I would reach my goal, but with it I end up losing several interesting threads, such as Thread.Synchronize and Thread.Queue , which, once again, , the weight of these losses becomes enormous.

An example setting via hardcode would already be enough, since I already have the form to parameterize this defined value.

    
asked by anonymous 18.03.2014 / 13:32

2 answers

1

I found a way to solve my problem without appealing to BeginThread . Following:

At the beginning of my project I can set the size of all threads of the system, consequently those created by the Thread.Execute method.

When adding rows:

{$MINSTACKSIZE 16384}
{$MAXSTACKSIZE 65536}

In this way:

Isettheminimumandmaximumsizeforeachthread.

Followevidence:

  

Before:   Stack size 1,000Kb
Next:    Stack size 64Kb

    
02.04.2014 / 18:24
3

Unfortunately, the class TThread does not allow configuring the stack size of the thread . The only way to achieve this would be to use the BeginThread function, however as you said it is not workable in your case.

  

function BeginThread (SecurityAttributes: Pointer; StackSize ).

The report was issued in 2009 who knows in the near future that this is a feature. :)

    
18.03.2014 / 14:41