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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:29:50+00:00 2026-06-16T00:29:50+00:00

I am writing a class that needs to support both volatile and non-volatile instances

  • 0

I am writing a class that needs to support both volatile and non-volatile instances (volatile instances use atomic operations, non-volatile instances use regular operations), and am wondering if I am going about it in the correct way. Here’s a snippit of the class declaration so far:

class Yield {
public:
    Yield();
    Yield(Yield const &other);
    Yield(Yield const volatile &other);

    Yield &operator=(Yield const &other);
    Yield &operator=(Yield const volatile &other);

    Yield &operator+=(Yield const &other);
    Yield &operator+=(Yield const volatile &other);
    Yield volatile &operator+=(Yield const &other) volatile;
    Yield volatile &operator+=(Yield const volatile &other) volatile;

    // Other operators snipped...
};
  • Question 1: When compiling with MSVC, I get the following warning:

    warning C4521: 'util::Yield' : multiple copy constructors specified

    Does this warning portend any problems in using this class? Or can it be safely ignored?

  • Question 2: As it stands, all operators are overloaded for both a volatile and non-volatile other argument. I assume this is necessary in order to avoid slower volatile accesses for non-volatile instances? Is there an alternative to allow each method to be coded only twice (volatile lhs and non-volatile lhs) rather than 4 times (volatile and non-volatile lhs, each with volatile and non-volatile rhs)?

I hope putting these questions together is ok, otherwise please leave a comment and I can split them.
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-06-16T00:29:51+00:00Added an answer on June 16, 2026 at 12:29 am

    Volatile does not do what you think it does.

    Even with VC++’s special, non-standard volatile behavior, it results in slower code than writing it properly. Use std::atomic, or if that’s not available then you’ve probably got platform-specific barrier, fence, and atomic intrinsics. VC++ has _ReadWriteBarrier and _Interlocked functions to help you.

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

Sidebar

Related Questions

I am writing a class that I know that needs a lock, because the
I apologize if this is a duplicate. I am writing a class that needs
I'm writing a class that returns both a DataTable and a IEnumerable. I cannot
I'm writing a factory class that should be able to return singleton instances of
Here is a simple thread pattern that I use when writing a class that
I'm writing a class that needs to attach event listeners to objects within a
I am writing an Objective-C class that needs to make function calls on a
I'm currently writing a class that needs os , stat and some others. What's
I am writing a program in C# that needs to support undo/redo. For this
I am writing a class using Qt that needs to import a dictionary that

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.