Boost Threads
Launching a threadPortable Headers#include <boost/thread.hpp>Launching a threadvoid find_the_question(intthe_answer); boost::thread deep_thought_2(find_the_question,42);
Launching a threadstruct 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 threadPassing member functions to thread objectm_thread = shared_ptr<thread>(new thread(bind(&CTimerThread::Execute, this)));
Thread CompletionJoin or timed_join member functions of thread objectJoin – waits for indefinite time for thread to complete – until the method on which the thread executes returnsTimed_join takes boost::posix_time as argumentm_thread->timed_join( boost::posix_time::microseconds(MAXTIMEOUT_IN_MS) );
Detaching a threadIf boost::thread object is destroyed, the thread is detached.Detached thread continues executing until program terminates or till function returnsdetach() member function of boost::thread object also detaches the thread object.
interruptA 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 IDget_id member function returns a unique id for the thread object.Portable way to sleepboost::this_thread::sleep(boost::posix_time::milliseconds(launchtime));
MutexVoid foo(){boost::mutex::scoped_lock l(m_mutex);//m_mutex is a boost::mutexobject//Critical section//Unlock happens automatically at end of scope}

More Related Content

PPTX
Multithreaded programming
PPTX
Python Training in Bangalore | Multi threading | Learnbay.in
PPTX
Presentation 6
PDF
Intro KaKao MRTE (MySQL Realtime Traffic Emulator)
PPTX
#2 (UDP)
PDF
OSGi Puzzlers
PPTX
Multithreading
PPTX
Network simulator 2
Multithreaded programming
Python Training in Bangalore | Multi threading | Learnbay.in
Presentation 6
Intro KaKao MRTE (MySQL Realtime Traffic Emulator)
#2 (UDP)
OSGi Puzzlers
Multithreading
Network simulator 2

What's hot (9)

PDF
Storm introduction
PPTX
Python library
PPT
Introduction to NS2 - Cont..
PPT
Oop lecture9 11
PPTX
Namespace1
PPTX
Introduction Big Data and Hadoop
PPTX
Psycopg2 - Connect to PostgreSQL using Python Script
PDF
20150207 howes-gpgpu8-dark secrets
PPT
Moar tools for asynchrony!
Storm introduction
Python library
Introduction to NS2 - Cont..
Oop lecture9 11
Namespace1
Introduction Big Data and Hadoop
Psycopg2 - Connect to PostgreSQL using Python Script
20150207 howes-gpgpu8-dark secrets
Moar tools for asynchrony!
Ad

Similar to Boost threads (20)

PPTX
Java concurrency - Thread pools
PPT
Python multithreading session 9 - shanmugam
PPT
Threads Advance in System Administration with Linux
PPTX
Multithreading with Boost Thread and Intel TBB
PPTX
multithreading to be used in java with good programs.pptx
PPTX
Generators & Decorators.pptx
PPT
Java concurrency
PPTX
Java Multithreading - how to create threads
PDF
اسلاید ارائه اول جلسه ۱۰ کلاس پایتون برای هکر های قانونی
PPT
multhi threading concept in oops through java
PPTX
Multi threading
PPTX
Threads
PDF
Do something in 5 with gas 7-email log
PDF
Intake 38 12
PPT
Session 7_MULTITHREADING in java example.ppt
PPT
Session 7_MULTITHREADING in java example.ppt
PPTX
Threading concepts
PPT
Java concurrency - Thread pools
Python multithreading session 9 - shanmugam
Threads Advance in System Administration with Linux
Multithreading with Boost Thread and Intel TBB
multithreading to be used in java with good programs.pptx
Generators & Decorators.pptx
Java concurrency
Java Multithreading - how to create threads
اسلاید ارائه اول جلسه ۱۰ کلاس پایتون برای هکر های قانونی
multhi threading concept in oops through java
Multi threading
Threads
Do something in 5 with gas 7-email log
Intake 38 12
Session 7_MULTITHREADING in java example.ppt
Session 7_MULTITHREADING in java example.ppt
Threading concepts
Ad

Recently uploaded (20)

PDF
IGGE1 Understanding the Self1234567891011
PDF
International_Financial_Reporting_Standa.pdf
PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
PDF
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
PPTX
20th Century Theater, Methods, History.pptx
PDF
Hazard Identification & Risk Assessment .pdf
PDF
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
PPTX
History, Philosophy and sociology of education (1).pptx
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
PPTX
Introduction to pro and eukaryotes and differences.pptx
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Uderstanding digital marketing and marketing stratergie for engaging the digi...
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
IGGE1 Understanding the Self1234567891011
International_Financial_Reporting_Standa.pdf
Unit 4 Computer Architecture Multicore Processor.pptx
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
Chinmaya Tiranga quiz Grand Finale.pdf
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
20th Century Theater, Methods, History.pptx
Hazard Identification & Risk Assessment .pdf
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
History, Philosophy and sociology of education (1).pptx
Paper A Mock Exam 9_ Attempt review.pdf.
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
Introduction to pro and eukaryotes and differences.pptx
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Uderstanding digital marketing and marketing stratergie for engaging the digi...
A powerpoint presentation on the Revised K-10 Science Shaping Paper
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf

Boost threads

  • 2. Launching a threadPortable Headers#include <boost/thread.hpp>Launching a threadvoid find_the_question(intthe_answer); boost::thread deep_thought_2(find_the_question,42);
  • 3. Launching a threadstruct 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}
  • 4. Launching a threadPassing member functions to thread objectm_thread = shared_ptr<thread>(new thread(bind(&CTimerThread::Execute, this)));
  • 5. Thread CompletionJoin or timed_join member functions of thread objectJoin – waits for indefinite time for thread to complete – until the method on which the thread executes returnsTimed_join takes boost::posix_time as argumentm_thread->timed_join( boost::posix_time::microseconds(MAXTIMEOUT_IN_MS) );
  • 6. Detaching a threadIf boost::thread object is destroyed, the thread is detached.Detached thread continues executing until program terminates or till function returnsdetach() member function of boost::thread object also detaches the thread object.
  • 7. interruptA 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?
  • 8. Thread IDget_id member function returns a unique id for the thread object.Portable way to sleepboost::this_thread::sleep(boost::posix_time::milliseconds(launchtime));
  • 9. MutexVoid foo(){boost::mutex::scoped_lock l(m_mutex);//m_mutex is a boost::mutexobject//Critical section//Unlock happens automatically at end of scope}