Threads with size set via code

Asked

Viewed 260 times

4

I have a system that at certain times uses more than a thousand threads simultaneous and unfortunately accurate run in environment 32-bits.

For default, the Delphi allocates 1kb for each thread new, what, in an environment 32-bits becomes unviable 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 big for them.

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

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

An example setando via hardcode even would be enough, since I already have the way to parameterize this defined value.

  • 1

    More than a thousand simultaneous threads seems excessive to me. Perhaps it would be better for you to create a Thread-pool, right? What do these threads do?

  • When you have a queue of almost 70,000 simultaneous commands, a pool of 1,000 doesn’t seem so excessive. I believe everything depends on the referential.

  • 1

    I believe that a lot depends on the referential and so I asked you for more information on the subject without condemning your work. What I do know is that 1,000 simultaneous threads is usually too much if you don’t have a cluster of 500 colors. Without more information it becomes difficult to help because I particularly don’t like to risk on kicks.

  • My comment was by no means derogatory, @Embarbosa, quite the contrary. By the impossibility of passing more information, I really failed to explain why so many simultaneous threads, so at this point I just made correct my previous error.

2 answers

3

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

Function Beginthread(Securityattributes: Pointer; StackSize: Longword; Threadfunc: Tthreadfunc; Parameter: Pointer; Creationflags: Longword; var Threadid: Tthreadid): Thandle;

There are even suggestions to change this see(Permitir que o tamanho da pilha seja especificado ao criar a thread - Embarcadero).

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

  • It is... Apparently there is no solution. I appreciate the effort. + 1

  • 1

    C. I found a way! Really, parameterize in function is impossible, but you can set the size for all threads and that solves the problem. I really appreciate the help!

1


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

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

When adding lines:

{$MINSTACKSIZE 16384}
{$MAXSTACKSIZE 65536}

In this way: Unit Stress

I set the minimum and maximum size of each thread.


Follows evidence:

Before: Antes Stack size 1.000Kb
Afterward: Depois Stack size 64kb

Browser other questions tagged

You are not signed in. Login or sign up in order to post.