Question

I'm trying to create a new thread by executing pthread_create with a single argument.

void P2FPanel::startRecording()
{
  qDebug() << "Start recording...";
  qDebug() << "_bag_list: " << _bag_list->size();
  pthread_create(&_playBags_t, NULL, playBags, _bag_list);
  qDebug() << ".... Started";
}

This method is triggered by a button and creates the pthread. Here the code already exits with error -11 (I think it's segmentation fault). The debug lines show that _bag_list is not empty.

void* P2FPanel::*playBags(void* arg0)
{
  qDebug() << "Play Bags from _bag_list...";
  QList<BagRef*> *bag_list = (QList<BagRef*>*) arg0;
  qDebug() << "Play " << QString("%1").arg(bag_list->size()) << " Bags";
  //Do stuff
  qDebug() << "Finished playing";
  return 0;
}

This method should run in a new thread.

class P2FPanel: public rviz::Panel
{

  private Q_SLOTS:
    void startRecording();

  private:
    QList<BagRef*> *_bag_list;
    void* (*playBags)(void* arg0);
    pthread_t _playBags_t;

};

The header file.

Where is the error coming from? Is the declaration of the threaded method correct?

Thanks in advance, best regards, Josch

Was it helpful?

Solution

As far as I remember, you cannot pass class-methods into pthreads. Consider: this and that. You should use static methods.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top