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

  • Home
  • SEARCH
  • 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 114943
In Process

The Archive Base Latest Questions

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

What are all the things one needs to be careful about when coding in

  • 0

What are all the things one needs to be careful about when coding in a multicore environment?

For example, for a singleton class, it is better to create a global object and then return its reference than a static object.

i.e Rather than having

MyClass & GetInstance() {  static Myclass singleMyclass; return singleMyclass; } 

It is better to have

Myclass singleMyclass;   MyClass & GetInstance()     {       return singleMyclass;     } 

GetInstance() might be called by many threads simultaneously.

Edit:

My question was about the hidden constructs of c++ one must be aware of while using them in multithreaded program. In above case static is not thread safe as compiler adds some instructions for static objects, which is not thread safe. I am looking for similar constructs one should be aware of.

  • 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. 2026-05-11T02:56:28+00:00Added an answer on May 11, 2026 at 2:56 am

    My first answer addressed your example of singleton initialisation, but as you emphasised in an edit to your question, you are after more general pit falls of C++ as we move to multi-core and multi-threaded applications. The following is a real surprise when you first encounter it. Though not C++ specific, it definitely affects C++ code.

    Out of order execution and Memory Barriers (or fences):

    One gotcha is out of order execution. It is possible for threads to see operations of other threads executing on different cores out of order due to modern hardware allowing out of order execution optimisation. As a result, multi-threaded coded that runs correctly on a single-core machine may in fact be incorrect on a multi-core machine.

    A naive solution to such problems is to increase the scope of critical sections. Another is to use memory barriers or lock-free algorithms.

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

Sidebar

Ask A Question

Stats

  • Questions 189k
  • Answers 189k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you really don't want the second command to proceed… May 12, 2026 at 5:46 pm
  • Editorial Team
    Editorial Team added an answer Try this function; ETA Okay, I'm an idiot and I… May 12, 2026 at 5:46 pm
  • Editorial Team
    Editorial Team added an answer See the SVN Book on External Diff Tools: The presence… May 12, 2026 at 5:46 pm

Related Questions

I'm working on a project that will (soon) be branched into multiple different versions
At work I see one colleague designing a site in Photoshop/Fireworks, I see another
What are your opinions on developing for the command line first, then adding a
I just wanted to see if I could have your thoughts on the design

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.