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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:26:50+00:00 2026-05-27T00:26:50+00:00

I have some code in a function that goes something like this: void foo()

  • 0

I have some code in a function that goes something like this:

void foo() {
    { // scope the locker
      MutexLocker locker(&mutex);
      // do some stuff..
    }
    bar();
}

The function call bar() also locks the mutex.

I am having an issue whereby the program crashes (for someone else, who has not as yet provided a stack trace or more details) unless the mutex lock inside bar is disabled.

Is it possible that some optimization is messing around with the way I have scoped the locker instance, and if so, would making the mutex volatile fix it? Is that a bad idea?

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-05-27T00:26:51+00:00Added an answer on May 27, 2026 at 12:26 am

    I don’t think someone can actually answer the question, as we (and so do you) haven’t seen the stack back-trace.

    Is it possible that some optimization is messing around

    Yes, it is, but it’s very, very unlikely. Maybe in more than 99% of the cases, the problem is in the code, not in the optimizations.

    However, it is possible that the compiler optimizations "unlock" some other bugs, most likely – undefined behavior, that works fine without optimizations and with them – the UB becomes a crash *

    making it volatile fix it? Is that a bad idea

    I don’t think it will fix anything and I don’t think you need volatile for this.
    I use wrapper around POSIX threads with class Mutex and class MutexLock, the logic is the same as in your case, and there’s no volatile in these classes (except some bool flags and the thread id, but this seems to be irrelevant to the case)


    "*" I recently had such case – when we compiled an application with -O2, strange crashes appeared. We investigated this for months, we couldn’t find anything suspicious. Then removed the optimizations and everything started working fine again.
    Several months later, I found the issue and it appeared to be multithreading one – returning const ref on a place, that we shouldn’t have done this.

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

Sidebar

Related Questions

I have some XML code that looks like this <SEARCHRESULTS> <FUNCTION name=BarGraph> <PARAMETER name=numList></PARAMETER>
I have some code that looks something like this: <head runat="server"> <script type="text/javascript"> var
I'd like to write a function that would have some optional code to be
I have some code in a couple of different functions that looks something like
I have some code that uses the Oracle function add_months to increment a Date
I have some jQuery code that intercepts links clicked on a page: $(document).ready(function() {
I have some jQuery code. I have called an Ajax function file, file.php, that
The code goes something like this: protected bool IsOKToSend() { bool IsOK = true;
Ok, so I have a file called functions.ps1 that contains only function code: something
Let's say I have something like this: <?php namespace Twitter; class Twitter { function

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.