Opened 12 years ago
Closed 11 years ago
#4894 closed Support Requests (worksforme)
segmentation fault on thread_group::join_all depending on the machine used
Reported by: | Owned by: | Anthony Williams | |
---|---|---|---|
Milestone: | To Be Determined | Component: | thread |
Version: | Boost 1.35.0 | Severity: | Problem |
Keywords: | Cc: |
Description
Hello I would like to submit this new ticket, hopping it is really a problem and not an error of my own.
I explain the problem, I made this simple program (just after) and, depending on the machine where I execute it, it makes a segmentation fault or not. I would like to know if it is because of the computer used or if it is really a bug.
The program :
#include <iostream> #include <boost/thread/thread.hpp> #include <boost/bind.hpp> using namespace std; const int thread_nbr=20; void fonct(int num){ cout << "thread " << num << endl; } int main(){ int i=0; int j=0; boost::thread_group groupe; for(i=0;i<5;i++){ cout << "beginning of loop " << i << ":" << endl; for(j=1;j<thread_nbr;j++){ groupe.create_thread(boost::bind(fonct,j)); } fonct(0); cout << "after fonct" << endl; cout << "waiting for join.all" << endl; groupe.join_all(); cout << "after join.all" << endl << endl; } return 0; }
The trace when it works (I have tested it on five different computers, one with one core, one with two cores, two with four cores, one with twelve cores, it didn't work for the one with twelve and one with four) :
beginning of loop 0: thread 1 thread 2 thread 3 thread 4 thread 5 thread 6 thread 7 thread 8 thread 9 thread 10 thread 11 thread 12 thread 13 thread 14 thread 15 thread 16 thread 17 thread 18 thread 19 thread 0 after fonct waiting for join.all after join.all beginning of loop 1: thread 1 thread 2 thread 3 thread 4 thread 5 thread 6 thread 7 thread 8 thread 9 thread 10 thread 11 thread 12 thread 13 thread 14 thread 15 thread 16 thread 17 thread 18 thread 19 thread 0 after fonct waiting for join.all Segmentation fault
On the other situations it works until the end.
If I put the "const int thread_nbr" to 4 instead of 20, it works on every machine I tried.
Apparently the problem come from the thread_group::join_all() function.
Could the thread_group make a problem on certain machines when the number of threads in the group is big ?
I Have tested it with boost 1.35 and boost 1.42.
Do you know where the problem can come from.
Is it a known problem maybe already solved in newer version of boost?
Thanks to care on my question, and sorry for my bad english.
Change History (4)
comment:1 by , 12 years ago
Component: | None → thread |
---|---|
Owner: | set to |
comment:2 by , 12 years ago
comment:3 by , 12 years ago
I confirm, if I do like you said, on the two machines where it didn't work, the program runs normally.
Well see, problem solved.
Thanks
comment:4 by , 11 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
Type: | Bugs → Support Requests |
I have not tried but I see a possible source of the problem: the groupe variable stores threads that are joined several times. Could you try to move the declaration inside the for?
Vicente