I am implementing a message passing algorithm. Messages are distributed through the nodes of the chart, blocking until they have received sufficient information (from other neighbors) to send the message.
It is easy to write the algorithm if I put each message in my stream and use the boost :: condition to pause the stream until all the necessary information is available. I create many thousands of threads, but in most cases, only some of them are active at any time. This seems to work very well.
My problem is that during unit testing, I found that if I create more than 32705 threads, I get
unknown location (0): fatal error in "Tree_test": std :: exception: raising :: thread_resource_error
, and I don’t know what causes this, or how to fix it.
It seems that there is available memory (each thread contains only two pointers - the objects through which the message passes).
From this question: What is the maximum number of threads for a process on Linux? I think the following information is relevant (although I really don't know what that means ...)
~> cat /proc/sys/kernel/threads-max 1000000
(I increased this from 60120 - do I need to restart?)
~>ulimit -a core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 20 file size (blocks, -f) unlimited pending signals (-i) 16382 max locked memory (kbytes, -l) 64 max memory size (kbytes, -m) unlimited open files (-n) 1024 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 8192 cpu time (seconds, -t) unlimited max user processes (-u) unlimited virtual memory (kbytes, -v) unlimited file locks (-x) unlimited
I tried to bother with waiting signals (my limit is very close to 2 * that number) and the stack size with ulimit -S -i 8191 - (I could not increase it), but these changes did not seem to affect at all)
I'm on 64 bit Ubuntu-10-10 if that helps ...