Boost logo

Boost Users :

From: Kevin Wheatley (hxpro_at_[hidden])
Date: 2005-03-22 04:28:50


Thorsten Froehlich wrote:
> > Why don't
> > you post an example that shows the behaviour you're reporting?
>
> As others have already understood the problem, there does not seem to be a
> need to do so.

something like:

#include <boost/thread/thread.hpp>
#include <iostream>

using namespace std;
using namespace boost;

void foo(void)
{

   // So it doesn't really matter what goes on here but
   // something causes the routine to exit...
   int i = 10000;
   while (true)
   {
      // in my case this 'signal' is a special terminate job
      // as we all know thread cancelation is 'hard'
      if (--i == 0) break;
   }

  // Once we leave here we have no idea when the join call will occur
}

int main(int argc, char** argv)
{
  thread fooThread(&foo);

  // Now do something to cause a delay here...

  // ignore the fact that input/output may not be 'thread safe' as
this is not the point!!
  std::cout << "press the 'any' key..." << std:endl;
  char dummy;
  std::cin >> dummy;

  // assert may fail during join as the foo thread may have exited,
but how do we know this?
  fooThread.join();
  return 0;
}

So I could have made the thread detatched, but then consider the case
when using thread_group, you've got multiple threads doing work and
you want them to stop for some reason, how do you do that safely? My
atificial delays above actually occur in operating systems

Kevin

-- 
| Kevin Wheatley, Cinesite (Europe) Ltd | Nobody thinks this      |
| Senior Technology                     | My employer for certain |
| And Network Systems Architect         | Not even myself         |

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