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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:00:51+00:00 2026-05-26T03:00:51+00:00

Though standard doesn’t guarantee the thread-safety for new , most of the multi-threading operating

  • 0

Though standard doesn’t guarantee the thread-safety for new, most of the multi-threading operating systems support thread-safe operator new.

I am implementing my own memory management for the dynamic allocation of certain class (say MyClass) in my code. For thread safety of MyClass, I may have to use pthread or boost:: library.

I thought that if new is already thread safe then I can overload that for MyClass and leverage its safety without worrying about using those libraries.

class MyClass {
// data
public:
  void* operator new (size_t);
  void operator delete (void*);
};

Is it a fair assumption for C++03 systems/compilers?

Edit: Since my question is not followed by few users. I am detailing that part:

If I have 2 threads which do new int() and new int(), then 2 unique memory addresses will be returned. Now, in my overloaded MyClass::new I am not using global ::new() or any threading library; but own memory manager (which doesn’t know anything about threads). Pseudo code:

char pool[BIG_SIZE];
void* MyClass::operator new (size_t size)
{
  // get some memory from 'pool' without using any thread library
  return p;
}

My assumption is, since global ::new is thread safe, this overloaded operator new also should be thread-safe. In other words, compiler should be emitting thread-safety related code wherever it encounters new keyword. Is this a correct assumption ?

  • 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-26T03:00:51+00:00Added an answer on May 26, 2026 at 3:00 am

    It is.

    However note that in C++11 new is thread safe.

    Of course, when you add thread unsafe code, it makes your operator new thread unsafe.

    Following your edit (which changed the whole question):

    The assumption that the compiler adds thread safety code around the new call is pretty wrong. Sane implementations will always add thread safety within the inner implementation of operator new (already because of efficiency considerations like per-thread memory pools).

    That is, when you write a thread unsafe allocation function, just by naming it operator new will not magically make it thread safe, as this is just like any other function, only with a special way to be invoked.

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

Sidebar

Related Questions

Though it's debatable, I've heard the majority of CSS developers prefer multi-line because of
Someone recently asked me the difference between a C++ standard operator (e.g. new,delete,sizeof) and
The WinForms GroupBox control doesn't support MouseMove (or at least, not consistently), and I
It looks like the standard asp.net 2 RangeValidator control doesn't allow times. e.g. 01/01/2008
I'm interested for C++, though I suspect that simply imports the C standard definition.
How do you iterate through every file/directory recursively in standard C++?
Is there any standard way of implementing some sort of a write-through buffer for
Though it's on the edge of programming questions, I think this is still relevant
Even though I always strive for complete validation these days, I often wonder if
Even though I have a robust and fast computer (Pentium Dual Core 2.0 with

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.