|
Boost Users : |
Subject: [Boost-users] [boost] [thread] thread handling question
From: Markus Pieper (onkelhotte_at_[hidden])
Date: 2016-06-02 04:07:53
Hi, this may be a very dumb question⦠My boost version is 1.56.0.
In my program I use a database logging technique. To avoid blocking the
main thread, I coded this:
int main()
{
  while(bDoCalculations == true)
{
     // calculate some stuff
     m_Logger->doLogging();
  }
}
void CLoggingData::doLogging() {
  std::vector<float>* Result;
  // fill Result boost::thread (&CLoggingData::doStoreData, this, Result);
}
void CLoggingData::doStoreData(std::vector<float>* dataVector) {
  // pass pointer to database writer instance
  delete dataVector;
}
I do not use join() in the doLogging method because I donât want the main
thread to block if the database is busy and will not respond immediately.
But then, after a long run I get a boost::thread_resource_error exception.
You may say: Of course, you never join your thread and after a few
thousands new threads you blow your stack.
Well, but what can I do to get my desired behavior? In the documentation I
found this which I think of might help:
You can use a thread_joiner to ensure that the thread has been joined at
the thread destructor.
int main()
{
  boost::thread t(my_func);
  boost::thread_joiner g(t);
  // do someting else
} // here the thread_joiner destructor will join the thread before it is
destroyed.
But where is the thread_joiner class implemented? Or do I have to add
something inside my doStoreData method to end the thread properly?
Thanks in advance,
Markus
Gesendet mit AquaMail für Android
http://www.aqua-mail.com
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net