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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:13:40+00:00 2026-05-15T19:13:40+00:00

Mmap returns a void*, but not a volatile void* . If I’m using mmap

  • 0

Mmap returns a void*, but not a volatile void*. If I’m using mmap to map shared memory, then another process could be writing to that memory, which means two subsequent reads from the same memory location can yield different values — the exact situation volatile is meant for. So why doesn’t it return a volatile void*?

My best guess is that if you have a process that’s exclusively writing to the shared memory segment, it doesn’t need to look at the shared memory through volatile pointers because it will always have the right understanding of what’s present; any optimizations the compiler does to prevent redundant reads won’t matter since there is nothing else writing and changing the values under its feet. Or is there some other historical reason? I’m inclined to say returning volatile void* would be a safer default, and those wanting this optimization could then manually cast to void*.

POSIX mmap description: http://opengroup.org/onlinepubs/007908775/xsh/mmap.html

  • 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-15T19:13:41+00:00Added an answer on May 15, 2026 at 7:13 pm

    The deeply-held assumption running through many software systems is that most programmers are sequential programmers. This has only recently started to change.

    mmap has dozens of uses not related to shared memory. In the event that a programmer is writing a multithreaded program, they must take their own steps to ensure safety. Protecting each variable with a mutex is not the default. Likewise, mmap does not assume that another thread will make contentious accesses to the same shared-memory segment, or even that a segment so mapped will be accessible by another thread.

    I’m also unconvinced that marking the return of mmap as volatile will have an effect on this. A programmer would still have to ensure safety in access to the mapped region, no?

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

Sidebar

Ask A Question

Stats

  • Questions 510k
  • Answers 510k
  • 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 Whenever a page doesn't render as I expect, the first… May 16, 2026 at 5:00 pm
  • Editorial Team
    Editorial Team added an answer (Now that schema has been provided, removed my sample schema… May 16, 2026 at 5:00 pm
  • Editorial Team
    Editorial Team added an answer If you are working with a variable that has a… May 16, 2026 at 5:00 pm

Trending Tags

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

Top Members

Related Questions

I allocated some memory with anonymous mmap: buff->addr = mmap(NULL, length, PROT_NONE, MAP_PRIVATE |
The OS I'm working on (IBM CNK, which is not Linux, but somewhat POSIX-compliant)
For my bachelor thesis i want to visualize the data remanence of memory and
When I check a singleton property that is nil, it kills my app. But
I am trying to create a debugfs file using the debugfs_create_file(...). I have written
I have written a function that checks if to files are duplicates or not.
I have a memory mapped file, from which I wish to parse the contents
I have a very simple class that opens a file and creates a memory
In our product we use a malloc implementation that relies exclusively on mmap for
Is it possible to change the name of an already open memory mapped file,

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.