• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Boost threads
 

Boost threads

on

  • 1,484 views

 

Statistics

Views

Total Views
1,484
Views on SlideShare
1,471
Embed Views
13

Actions

Likes
0
Downloads
0
Comments
0

1 Embed 13

http://fromhelloworld.wordpress.com 13

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Boost threads Boost threads Presentation Transcript

    • Boost Threads
    • Launching a thread
      Portable
      Headers
      #include <boost/thread.hpp>
      Launching a thread
      void find_the_question(intthe_answer);
      boost::thread deep_thought_2(find_the_question,42);
    • Launching a thread
      struct callable { void operator()(); };
      boost::thread make_thread()
      {
      callable x;
      return boost::thread(x);
      // x is destroyed, but the newly-created thread has a copy, so this is OK
      }
    • Launching a thread
      Passing member functions to thread object
      m_thread = shared_ptr<thread>(new thread(bind(&CTimerThread::Execute, this)));
    • Thread Completion
      Join or timed_join member functions of thread object
      Join – waits for indefinite time for thread to complete – until the method on which the thread executes returns
      Timed_join takes boost::posix_time as argument
      m_thread->timed_join( boost::posix_time::microseconds(MAXTIMEOUT_IN_MS) );
    • Detaching a thread
      If boost::thread object is destroyed, the thread is detached.
      Detached thread continues executing until program terminates or till function returns
      detach() member function of boost::thread object also detaches the thread object.
    • interrupt
      A running thread can be interrupted by invoking the interrupt() member function of the corresponding boost::thread object.
      For specified interruption points like join or sleep, the interrupted thread throws boost::thread_interrupted exception.
      SuspendThread or ResumeThread not supported?
    • Thread ID
      get_id member function returns a unique id for the thread object.
      Portable way to sleep
      boost::this_thread::sleep(boost::posix_time::milliseconds(launchtime));
    • Mutex
      Void foo()
      {
      boost::mutex::scoped_lock l(m_mutex);
      //m_mutex is a boost::mutexobject
      //Critical section
      //Unlock happens automatically at end of scope
      }