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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:21:33+00:00 2026-05-29T08:21:33+00:00

I’m constantly reading from a memory mapped file another process is writing to and

  • 0

I’m constantly reading from a memory mapped file another process is writing to and use a mutex to synchronize this operation. In my few tests so far this works just fine, but… what if my application crashes right after acquiring the mutex and before releasing it? Is there any way to guarantee a release of the mutex, even in case of such a crash?

Also how would I handle a crash of the other process, which might not have released the mutex yet? Do I need to handle AbandonedMutexException each time I call mutex.WaitOne()?

Right now I’m doing it similar to this:

public MyState GetState()
{
    MyState state = new State();
    this._mutex.WaitOne();
    try
    {
        state.X = this._mmView.ReadSingle(0);
        state.Y = this._mmView.ReadSingle(4);
        [..]
    }
    finally
    {
        this._mutex.ReleaseMutex();
    }
    return state;
}

_mmView is a MemoryMappedViewAccessor I instantiated before. This whole method GetState() gets called each frame as part of a game loop, so about every few milliseconds.

PS: Also, is there any other obvious problem why this could fail, that I didn’t already mention?

  • 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-29T08:21:36+00:00Added an answer on May 29, 2026 at 8:21 am

    Eugen’s answer is correct — the operating system will release the mutex for you. Now think hard about what the consequences of this fact are:

    • You took out the mutex to ensure that no one would mutate state while you were reading, or read state while you were mutating. Let’s suppose the latter.
    • Another application wants to read the state, so it tries to take the mutex. It is forced to wait.
    • You mutated some state and then crashed.
    • The operating system released the mutex.
    • The other application now immediately acquires the mutex, and is now effectively reading state “while” another process is mutating it. The fact that the other process is now dead and gone means that the bogus state will now last forever, and the reading process will probably itself crash and die horribly. You have just defeated the safety system provided by the mutex.

    In short, you are worrying about exactly the wrong thing. You shouldn’t be worried about what happens if my mutex never gets released. The worst thing that happens then is everyone waits forever, which is sad, but eventually the user will reboot the machine. You should be worried about what happens if mutex does get released because I crashed halfway through a mutation. In that scenario processes will now probably be crashing all over the place and the user’s data will be permanently corrupted.

    Don’t get into that situation in the first place. The solution to the problem is do not crash when you have taken out a mutex for writing. If you don’t write programs that crash then you don’t have to worry about it, because its not going to happen. So just don’t write programs that ever crash.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from

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.