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 7522221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:27:35+00:00 2026-05-30T02:27:35+00:00

is boost::thread object thread-safe? Should I lock calling of member methods of boost::thread (e.g.

  • 0

is boost::thread object thread-safe? Should I lock calling of member methods of boost::thread (e.g. join) to be thread-safe?

EDIT 1: Please don’t bother with my purpose. Can you simply answer the question?

EDIT 2 (for those who are not satisfied with EDIT 1):
My purpose is:
Consider one procedure as program for the thread, one procedure which stops that thread. Thread procedure is a while loop checking condition whether to continue. Stop procedure sets the condition to FALSE and wait to the end of the thread (join) and then perform some other actions. The point is that the stop procedure can call more than one thread.

But my question is general, consider some next billion threads calling simultaneously member methods of one thread object such as get_id(), native_handle() etc.

  • 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-30T02:27:37+00:00Added an answer on May 30, 2026 at 2:27 am

    Joining a thread should only be done from a single other thread (preferably the thread that started it). There is no point for thread-safety in this case

    Ok, I’ve actually looked through the source code of boost::thread:

    void thread::join()
    {
        detail::thread_data_ptr const local_thread_info=(get_thread_info)();
        if(local_thread_info)
        {
            bool do_join=false;
    
            {
                unique_lock<mutex> lock(local_thread_info->data_mutex);
                while(!local_thread_info->done)
                {
                    local_thread_info->done_condition.wait(lock);
                }
                do_join=!local_thread_info->join_started;
    
                if(do_join)
                {
                    local_thread_info->join_started=true;
                }
                else
                {
                    while(!local_thread_info->joined)
                    {
                        local_thread_info->done_condition.wait(lock);
                    }
                }
            }
            if(do_join)
            {
                void* result=0;
                BOOST_VERIFY(!pthread_join(local_thread_info->thread_handle,&result));
                lock_guard<mutex> lock(local_thread_info->data_mutex);
                local_thread_info->joined=true;
                local_thread_info->done_condition.notify_all();
            }
    
            if(thread_info==local_thread_info)
            {
                thread_info.reset();
            }
        }
    }
    

    And it appears that yes, it is thread-safe.

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

Sidebar

Related Questions

I'm using an object to start boost thread and it has some public member
Circular_buffer from boost library is not thread-safe. So I wrapped boost::circular_buffer object in a
I have a object cache class like this: #include boost/thread/mutex.hpp #include boost/unordered_map.hpp template <typename
Suppose I have code something like this: #include boost/thread/mutex.hpp using boost::mutex; typedef mutex::scoped_lock lock;
Does anybody know of a fully thread-safe shared_ptr implementation? E.g. boost implementation of shared_ptr
I wanted to use boost::thread in my program, but get the following compiler error
I am using wxwidgets together with boost::thread. The Thread is a worker thread which
A portable thread specific storage reference/identity mechanism, of which boost/thread/tss.hpp is an instance, needs
I am experiencing a crash while using the Boost.Spirit and Boost.Thread libraries in my
I was trying to access a wxDialog members from a boost::thread: void AnotherThread(myWxDialog *dlg)

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.