Return Double from Boost thread

Posted by Benedikt Wutzi on Stack Overflow See other posts from Stack Overflow or by Benedikt Wutzi
Published on 2011-03-01T14:59:35Z Indexed on 2011/03/01 15:24 UTC
Read the original article Hit count: 276

Hi I have an Boost thread which should return a double. The function looks like this:

void analyser::findup(const double startwl, const double max, double &myret){
  this->data.begin();
  for(int i = (int)data.size() ; i >= 0;i--){
    if(this->data[i].lambda > startwl){
      if(this->data[i].db >= (max-30)) {
        myret = this->data[i+1].lambda;
        std::cout <<"in thread " << myret << std::endl;
        return;
      }
    }
  }
}

this function is called by another function:

void analyser::start_find_up(const double startwl, const double max){
  double tmp = -42.0;
  boost::thread up(&analyser::findup,*this, startwl,max,tmp);
  std::cout << "before join " << tmp << std::endl;
  up.join();
  std::cout << "after join " << tmp << std::endl;
}

Anyway I've tried and googled almost anything but i can't get it to return a value.

The output looks like this right now.

before join -42
in thread 843.487
after join -42

Thanks for any help.

© Stack Overflow or respective owner

Related posts about multithreading

Related posts about double