Changes between Initial Version and Version 2 of Ticket #7540


Ignore:
Timestamp:
Oct 23, 2012, 4:09:17 PM (10 years ago)
Author:
viboes
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #7540

    • Property Status newassigned
  • Ticket #7540 – Description

    initial v2  
    11Based on the thread_guard class defined in C++ Concurrency in Action define a helper class that interrupts and join a thread on destruction.
     2
     3
     4{{{
     5
     6// Based on the Anthony's idea of thread_guard in CCiA
     7
     8namespace boost
     9{
     10
     11  class thread_guard
     12  {
     13    thread& t;
     14  public:
     15    BOOST_THREAD_NO_COPYABLE( thread_guard )
     16
     17    explicit thread_guard(thread& t_) :
     18      t(t_)
     19    {
     20    }
     21    ~thread_guard()
     22    {
     23#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
     24      t.interrupt();
     25#endif
     26      if (t.joinable())
     27      {
     28        t.join();
     29      }
     30    }
     31  };
     32
     33}
     34
     35}}}