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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:08:06+00:00 2026-06-13T19:08:06+00:00

I was wondering about the safety of using boost::fast_pool_allocator with null_mutex set. I know

  • 0

I was wondering about the safety of using boost::fast_pool_allocator with null_mutex set.

I know that the following is an unsafe instance. An allocator is instantiated per type. So if you have two containers which both use fast_pool_allocator<int, …null_mutex> (say), they will both share the same allocator instance, and hence invite data races.

A greater concern is the following. The allocator interface allows rebinding. This means that even though you think you are using the fast_pool_allocator with a ‘local’ type which is unlikely to collide with other instances, a container is free to rebind that allocator to a different type, such as a global one, which does collide.

So the question is: Just how safe is boost::fast_pool_allocator with null_mutex?

  • 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-06-13T19:08:07+00:00Added an answer on June 13, 2026 at 7:08 pm

    I believe that both pool_allocator and fast_pool_allocator are thread safe,

    from: http://www.boost.org/libs/pool/doc/html/header/boost/pool/pool_alloc_hpp.html

    pool_allocator and pool_allocator will both
    allocate/deallocate from/to the same pool.

    As will the fast_pool_allocator

    If there is only one thread running before main() starts and after
    main() ends, then both allocators are completely thread-safe.

    however they are not very performant compared to other ways of decreasing allocation overhead. I have also been looking at tcmalloc from google which creates per thread heaps to avoid locking.

    The default for this parameter is boost::details::pool::default_mutex
    which is a synonym for either
    boost::details::pool::null_mutex (when threading support is
    turned off in the compiler (so BOOST_HAS_THREADS is not set), or
    threading support has ben explicitly disabled with
    BOOST_DISABLE_THREADS (Boost-wide disabling of threads) or
    BOOST_POOL_NO_MT (this library only)) or for boost::mutex
    (when threading support is enabled in the compiler).

    boost::mutex
    

    was set for me which is why in my threaded tests I had no issue – I would guess that this will be set correctly for you also.

    But if not then you could have an issue because:

    Since the size of T is used to determine the type of the underlying
    Pool, each allocator for different types of the same size will share
    the same underlying pool. The tag class prevents pools from being
    shared between pool_allocator and fast_pool_allocator. For example, on
    a system where sizeof(int) == sizeof(void *), pool_allocator and
    pool_allocator will both allocate/deallocate from/to the same
    pool.

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

Sidebar

Related Questions

Wondering about how to do the following efficiently, securely, and in a fashion that
I have been wondering about the following lines of code [self performSelector:@selector(myMethod) withObject:self afterDelay:1.0];
I was wondering about how saving variables work by using SharedPreferences inside onStop() function.
Im wondering about speed optimization in PHP. I have a series of files that
Ok, recently I've been thinking about thread safety a lot and I was wondering
I was wondering about the best way to setup to following. I have a
I wondering about sense of using XmlDocument class to processing a small XML files.
Just wondering about this... I have several separate javascript files, that all contain code
I'm wondering about http://www.woostercollective.com They have some nice responsive transitions that occurs when window
I'm wondering about the proper 'contract' or best practice for using IO objects in

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.