Is there some way to reduce memory cost of threads
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Is there some way to reduce memory cost of threads
Fedora15 32bit.
I write a test program, it creates new thread continually, the thread does nothing but sleep.
I find virtual memory increases up almost 10Mb when a new thread is created. and when there's more than 200 threads, the virtual memory used by the program is 3Gb, and now cann't create new thread.
but on windows, it costs little memory.
What can I do to config the operation system to take less memory on threads?
The trick is to keep track of your threads. Dont expect Linux to wave a magic wand and poof them away... because, well, when is a thread "not needed"???
In the "other one", it is possible to keep stuffing the thing until you overwrite something. Did that once, and got a "boot error" - and a dead os...but, those were bad times (I had to develop for the "thing)...
You need to find a way to let the main/calling system know what thread can be killed and get it to kill that thread too...
Linux works for you, it does not persé decide what has to be done, it is your system, you're not its appendix...
It would be nice to see this test program, namely to see which programming language you are using. Also, what tool are you using to measure the amount of (virtual) memory being consumed?
If you are developing in C, then the successful completion of a thread should be followed by a call to pthread_join(). That should release any resources used by the thread.
It would be nice to see this test program, namely to see which programming language you are using. Also, what tool are you using to measure the amount of (virtual) memory being consumed?
If you are developing in C, then the successful completion of a thread should be followed by a call to pthread_join(). That should release any resources used by the thread.
I use c++, Qt framework. use QThread to create thread.
I found that after ulimit -s 1024, it will take less memory.
I use c++, Qt framework. use QThread to create thread.
I found that after ulimit -s 1024, it will take less memory.
Why not skip the Qt threads and just use pthreads? It seems like the Qt thread class is meant for writing code that isn't limited to *nix operating systems. You can also look at man 2 clone for a more "customized" version if you really want to get your hands dirty.
Kevin Barry
Stop and consider how many hamburgers a group of about eight people can serve during a typical lunch hour, and how many hundreds of people can be placing those orders. Yet, "everything works," because the workflow (i.e. burgers) is not related to the number of workers who are doing the job.
If fast-food restaurants worked like too-many web sites do, the scenario would be like this:
You walk into the store.
The owner of the store pulls out a red box and pours a drop of water on it.
"Just Add Water!" A new employee magically appears!!
The employee takes your order, then walks into a crowded kitchen full of similar employees and starts slugging it out, trying to get your order ready.
The employee hands you your burger, then drops dead on the spot.
Why not skip the Qt threads and just use pthreads? It seems like the Qt thread class is meant for writing code that isn't limited to *nix operating systems. You can also look at man 2 clone for a more "customized" version if you really want to get your hands dirty.
Kevin Barry
I use QThread for the test program, in fact, our project use pthread_create.
Stop and consider how many hamburgers a group of about eight people can serve during a typical lunch hour, and how many hundreds of people can be placing those orders. Yet, "everything works," because the workflow (i.e. burgers) is not related to the number of workers who are doing the job.
If fast-food restaurants worked like too-many web sites do, the scenario would be like this:
You walk into the store.
The owner of the store pulls out a red box and pours a drop of water on it.
"Just Add Water!" A new employee magically appears!!
The employee takes your order, then walks into a crowded kitchen full of similar employees and starts slugging it out, trying to get your order ready.
The employee hands you your burger, then drops dead on the spot.
thanks, sundialsvcs. your example is very lively.
our program is a realtime network program, it works well on Windows for many years, these days we migrated it to Linux, and get the problem.
We solved it by setting stack size of Linux at last. and we needn't to change our code.
Windows uses an entirely different thread-management protocol, and manages its affairs very differently especially with regards to memory. (Read some docs in the Wine project for a discussion of some of those.)
IMHO, your "solution" is at best a temporary workaround and management needs to know that redesign of this aspect of the application needs to become a high-priority budget item. The project does not have to be unmercifully costly, and it will reap significant performance and therefore business benefits. (The same reasoning would greatly improve the Windows application, too, if it is also still in service.)
On either system, this design is over-committing the system and doing so without adequate controls, opening the way e.g. to a denial of service. Linux/Unix is simply making you pay the price more visibly.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.