Ask Your Question

pthread-related crashes

asked 2012-02-16 09:26:44 -0600

Robin gravatar image

Hi all,

I'm running ROS electric on a 24-core machine and having some issues with pthread under specific conditions. I use a class named ObjectTracker to handle ROS callbacks and sometimes use pthread to run some code in parallel without a problem. However, ObjectTracker includes instances of another class called Model, and Model includes functions that use pthread, as well. When Model tries to use pthread, the code usually crashes. I've tried using spin, multithreadspinner, and asyncspinner in ObjectTracker, and I still get the crashes. I'm also not trying to use more than 24 cores when it crashes. Even if I'm only trying to use on thread, but as long as it's created with pthread within Model and not ObjectTracker, it's a problem. Here's the specific code that is problematic:

// create threads
pthread_attr_t attr;
int rc;
void* status;

int count_thread = 0;
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
    for(int i=count_thread;i<min(count_thread+simultaneous_threads,num_threads);i++)
        pthread_create(&threads[i], &attr, thread_align_cloud_init, (void *) &aligndata[i]);

    // wait for the threads to execute
    for(int i=count_thread;i<min(count_thread+simultaneous_threads,num_threads);i++)
        rc = pthread_join(threads[i], &status);


Any help would be appreciated!!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2012-02-17 04:25:13 -0600

updated 2012-02-17 04:27:56 -0600

Issues with multi-threaded programs are usually caused by parallel accesses to shared data structures. Especially STL containers will die in a horrible way if two threads modify them simultaneously, or if a thread accesses them while another thread is writing to them.

Your code looks fine to me (provided the threads array is large enough to hold all handles) and is probably not the source of your problem. Off the top of my head, I'd suggest you take a look at thread_align_cloud_init and verify that anything that is not a local variable is either protected by a mutex or never accessed by two different threads. If other functions are called, the same rule applies to them as well.

edit flag offensive delete link more


I think the problem was that both threads were reading from the same point clouds. Even though they weren't editing the clouds, that was enough to cause some access issues. Thanks for pointing me in the right direction.

Robin gravatar image Robin  ( 2012-02-22 07:50:31 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2012-02-16 09:26:44 -0600

Seen: 625 times

Last updated: Feb 17 '12