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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:15:16+00:00 2026-05-28T01:15:16+00:00

If a global variable is shared across 2 concurrently running threads on 2 different

  • 0

If a global variable is shared across 2 concurrently running threads on 2 different cores, is there is possibility of data race or unexpected value even if the access to the shared variable is governed by critical section? Do I need to declare the variable atomic(volatile)? Each core might have a value of the shared variable in its cache and when one threads writes to its copy in a cache the other thread on a different core might read stale value from its cache after thread 1 releases the lock. Do the compiler generate code for volatile read/writes for the variables governed by critical sections or mutex by default?

  • 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-28T01:15:16+00:00Added an answer on May 28, 2026 at 1:15 am

    If all accesses to a shared variable are protected by the same mutex or critical section then this will avoid data races and unexpected values on that variable, even if the threads are on different cores. The lock and unlock functions of the mutex will include the necessary synchronization instructions to ensure that the caches are correctly synchronized across the processor cores. Within the locked region the normal instructions can be used to access the shared variables.

    There is no need to declare shared variables as atomic unless you are intending to access them without the protection of a mutex.

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

Sidebar

Related Questions

A global variable is shared across 2 concurrently running threads on 2 different cores.
i declare a global variable and use and modify its value in the function.
I know that it's possible to share a global variable across modules in Python.
I am developing a shared library(.so) and dll. I have a global variable which
Which of the following components of program state is shared across threads in a
In an .h file, I am declaring a global variable as: #pragma data_seg(.shared) #ifndef
I have 2 threads and a shared float global. One thread only writes to
Assume there are two threads running Thread1() and Thread2() respectively. The thread 1 just
Are session variables in the global $_SESSION array shared across scripts? Lets say I
Regarding global variable initialization, function hello_testing() { global $conditional_random; if (isset($conditional_random)) { echo foo

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.