Pthreads - High memory usage?

Not sur eit will help, but try calling setrlimit with RLIMIT_STACK to limit the stack size to 16k before creating your first thread.

2 16 kb may be too small, so ulimit -s 40 and ulimit -s 70 should be tried too. – osgx Aug 30 at 8:15 2 @osgx: the commands you suggested did the trick, thanks. I didn't try with setrlimit, but I guess it'll work too since it's based on the same.

Now I can open a lot of threads having a low memory usage. It looks that pthread_attr_setstacksize wasn't working as expected and a change on the global limit was needed – NeDark Aug 31 at 23:57 ulimit just calls setrlimit, so yes, it should work too :-) – gby Sep 2 at 13:26.

Yeah, it's fairly common for pretty much any operating system to choke and die on that many threads. It's not a problem that OS makers (Linux or otherwise) have given much attention to since very few systems have that many CPUs, so your code wouldn't likely executing much faster with 100 threads than it would with 8 (or however many CPUs you have). I think what you need to do is some sort of thread pooling.

I also suspect the ulimit answer on this page would be useful if you really need that many threads, but like I said, I don't think that many threads gets you much in most circumstances and if you fix it in your program instead of in the system, it'll make it more portable.

It is integer. Try to set it to 32 or 64 kilobytes, because 16*1024 may be not allowed; there can be also TLS in the stack (even you doesn't use TLS; libraries do, including libc). So, change the line to stacksize = 64*1024; and check how much memory is consumed.

16KB is the minimum stack size acording to kernel.org. Certainly, that double is incorrect there, I should put it by mistake. I'll try how it works with that correction, thanks.

– NeDark Aug 30 at 22:15 Finally the correction had no effect. – NeDark Aug 31 at 23:53.

The system threads library is just not designed to support large numbers of threads on systems with very limited memory. You need to either use a threading library designed for that purpose or, better, use fewer threads.

If you want lower overheads consider user-space threading technologies such as fibers, ala co-operative task management. en.wikipedia.org/wiki/Fiber_(computer_sc...) evanjones.ca/software/threading.html msdn.microsoft.com/en-us/library/ms68266...).aspx.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions