I implemented the thread pool because we can do some other stuff with the threads.

But we use the scoped threads in another area now.

Thanks for the advice!
Markus

Gesendet mit AquaMail für Android
http://www.aqua-mail.com

Am 3. Juni 2016 12:47:24 vorm. schrieb "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>:

Le 02/06/2016 à 10:07, Markus Pieper a écrit :
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?
Sorry, the documentation is erroneous. It should be boost::scoped_thread<>.

http://www.boost.org/doc/libs/1_56_0/doc/html/thread/ScopedThreads.html

HTH,
Vicente
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users