Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6112933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:48:04+00:00 2026-05-23T14:48:04+00:00

Why do we need boost::thread_specific_ptr, or in other words what can we not easily

  • 0

Why do we need boost::thread_specific_ptr, or in other words what can we not easily do without it?

I can see why pthread provides pthread_getspecific() etc. These functions are useful for cleaning up after dead threads, and handy to call from C-style functions (the obvious alternative being to pass a pointer everywhere that points to some memory allocated before the thread was created).

In contrast, the constructor of boost:thread takes a callable class by value, and everything non-static in that class becomes thread local once it is copied. I cannot see why I would want to use boost::thread_specific_ptr in preference to a class member any more than I would want to use a global variable in OOP code.

Do I horribly misunderstand anything? A very brief example would help, please. Many thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:48:05+00:00Added an answer on May 23, 2026 at 2:48 pm

    thread_specific_ptr simply provides portable thread local data access. You don’t have to be managing your threads with Boost.Thread to get value from this. The canonical example is the one cited in the Boost docs for this class:

    One example is the C errno variable,
    used for storing the error code
    related to functions from the Standard
    C library. It is common practice (and
    required by POSIX) for compilers that
    support multi-threaded applications to
    provide a separate instance of errno
    for each thread, in order to avoid
    different threads competing to read or
    update the value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use boost::thread_specific_ptr but need to know what to add to my
I need to convert several million dates stored as wide strings into boost dates
I'm new in using boost and have a problem. I need shared_mutex function in
i'm in a situation where i need to get boost::thread::id into a variable, but
See the following code: boost::thread_group threads; boost::barrier barrier(10); thing pThing; for( size_t i =
JDK's concurrency package, Boost's thread library, Perl's Thread library (not in Python though) all
Hi again with a boost question: I need to calculate the time spent in
So I have done some research, and have found you can create a boost::thread
In my thread (using boost::thread) I need to retrieve the current time in ms
boost:: asio provides an example of how to use the library to implement asynchronous

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.