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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:40:52+00:00 2026-06-14T23:40:52+00:00

This is a question about the C++ standard. I only have access to the

  • 0

This is a question about the C++ standard. I only have access to the draft standard so if this is different in the official one, I apologise. Also if I’ve misunderstood how this works please feel free to correct me.

Assume I have two threads, one writing to a string and one making a copy of the contents of that string. I protect access to them using a std::mutex myMutex;
I know you should in general use the RAII classes for locks, I just used lock and unlock explicitly to make the example more explicit.

// Global variable
std::string message;
std::mutex myMutex;

// Thread one
myMutex.lock();
message = "Hello";
myMutex.unlock();

// Thread two
myMutex.lock();
std::string copy = message;
myMutex.unlock();

My understanding is that in order for this to work reliably between threads, thread one must perform a Release operation after setting the string, and thead two must perform an Acquire before reading the string.

Reading the draft standard for C++11 I can’t see anything that states that std::mutex does this, although it’s fairly obvious that it’s expected to or the mutex would be useless for anything.

Can someone point me to the relevent section to look at? The wording in the standard is often not exactly clear to a casual reader 🙂

  • 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-14T23:40:53+00:00Added an answer on June 14, 2026 at 11:40 pm

    Per 30.4.1.2p11,

    Synchronization: Prior unlock() operations on the same object shall synchronize with (1.10) [m.lock()].

    Under 1.10p5,

    […] For example, a call that acquires a mutex will perform an acquire operation
    on the locations comprising the mutex. Correspondingly, a call that releases the same mutex will perform a release operation on those same locations. Informally, performing a release operation on A forces prior side effects on other memory locations to become visible to other threads that later perform a consume or an acquire operation on A. […]

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

Sidebar

Related Questions

Another question about the C standard. I have tested this and I always get
This question about Timers for windows services got me thinking: Say I have (and
Note: I originally asked this question about an hour ago but only recently realized
I have seen this question about deploying to WebSphere using the WAS ant tasks.
I have a question about the SQL standard which I'm hoping a SQL language
I have seen a question on here about this however it was old so
I have a question about some C++ standard compliance or lack of it. In
I have this classic question of how should the C++ Standard (I mean the
I have a question about forms. I have a fairly standard form that saves
This is an subjective question, I need your feels and thoughts about coding standards,

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.