Open In App

How does Volatile qualifier of C works in Computing System

Last Updated : 28 Jul, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

Prerequisite: Computing systems, Processing unit

Processing Unit:

  • Processing units also have some small memory called registers.
  • The interface between the processor (processing unit) and memory should work on the same speed for better performance of the system.

Memory:

In memory, there are two types, SRAM and DRAM. SRAM is costly but fast and DRAM is cheap but slow. Initial days the SRAM was used as memory. When the memory size started to increase the DRAM usage was increased and today only DRAM is used as the main memory.

Over the period the processor speed got increased but the memory speed wasn’t. So the system performance was not increased even the processor speed was increased. To solve the problem designers have introduced high-speed SRAM in between Processor and Main Memory.

This Memory is called cache. Since the SRAM is expensive, the size of the SRAM is small. It stores only the most recent access from main memory. To store the most recent access and check whether the content is available in Cache the Cache Controller is included in the design.

The processor can disable the cache controller as a whole or it can instruct the Cache controller to cache or not to cache any specific block of memory.

Below an example of data storing in memory:

C




// C program to execute for loop 100 times
#include <stdio.h>
  
// Driver Code
int main()
{
    int i, j;
    j = 0;
  
    // For loop execute 100 times
    for (i = 0; i < 100; i++) {
        j = j + i;
    }
    return 0;
}


Explanation:
In the above code, when the for loop is executed 100 times, the first time the variables are fetched from Main Memory and remaining 99 times the variables are fetched from Cache Memory. So the performance is improved. This is called Cache Hit and Cache Miss. In this case Cache hit is 99% and Cache miss is 1%. By default, the cache controller is enabled to improve the performance.

Let us discuss two cases:

Case 1: The main memory is shared between the Processor and a Controller.


In this case, if the cache is enabled for the block of memory shared by the Processor and Controller, and if the cache controller cache the block of the shared memory then updates by the controller in shared memory will not be known to the Processor. The processor will get the data from the Cache memory only. So this shared memory area needs to be disabled from the cache. So the processor needs to instruct the cache controller to do this job. A volatile qualifier does this job.

Case 2: The processor is reading & writing the controller registers.

In this case, if the controller registers changed due to do some internal function, that will be read by the processor. This Controller registers memory locations that need to disable from caching. In this case, also volatile qualifier is used.


Similar Reads

Understanding "volatile" qualifier in C | Set 2 (Examples)
The volatile keyword is intended to prevent the compiler from applying any optimizations on objects that can change in ways that cannot be determined by the compiler. Objects declared as volatile are omitted from optimization because their values can be changed by code outside the scope of current code at any time. The system always reads the curre
6 min read
Understanding "volatile" qualifier in C | Set 1 (Introduction)
In spite of tons of literature on C language, "volatile" keyword is somehow not understood well (even by experienced C programmers). We think that the main reason for this is due to not having real-world use-case of a 'volatile' variable in typical C programs that are written in high level language. Basically, unless you're doing some low level har
5 min read
Volatile data collection from Window system
Volatile data is the data that is usually stored in cache memory or RAM. This volatile data is not permanent this is temporary and this data can be lost if the power is lost i.e., when computer looses its connection. During any cyber crime attack, investigation process is held in this process data collection plays an important role but if the data
3 min read
Classical Computing vs Quantum Computing
Introduction : The conventional method of computing is the most popular method for solving the desired problem with the estimated time complexities. Algorithms of searching, sorting and many others are there to tackle daily life problems and are efficiently controlled over time and space with respect to different approaches. For example, Linear Sea
4 min read
Conventional Computing vs Quantum Computing
We've been using computers since early 19th century. We're currently in the fourth generation of computers with the microprocessors after vacuum tubes, transistors and integrated circuits. They were all based on conventional computing which is based on the classical phenomenon of electrical circuits being in a single state at a given time, either o
4 min read
Difference between Soft Computing and Hard Computing
The main difference between Soft Computing and Hard Computing is their approach to solving complex problems: Hard Computing: Hard computing uses traditional mathematical methods to solve problems, such as algorithms and mathematical models. It is based on deterministic and precise calculations and is ideal for solving problems that have well-define
2 min read
Quantum Computing - The Computing Technology of Tomorrow
Quantum Computing is a subject that can boggle even the most genius minds!!! It deals with topics that are considered science fiction by normal people like parallel universes, multiverse theory, etc. In fact, it sounds more like the next Marvel Dr. Strange movie and less like an actual technology!!! But Quantum Computing is very real. It is a compu
8 min read
Distributed Objects Computing: The next generation of client-server computing
Software technology is in the midst of a major computational shift towards distributed object computing DOC. Distributed computing is poised for a second client-server revolution, a transition from first generation client-server era to the next generation client-server era. In this new client-server model, servers are plentiful instead of scarce(be
2 min read
Difference Between Edge Computing and Fog Computing
Cloud computing refers to the on-demand delivery of IT services/resources over the internet. On-demand computing service over the internet is nothing but cloud computing. By using cloud computing users can access the services from anywhere whenever they need. Nowadays, a massive amount of data is generated every second around the globe. Businesses
4 min read
Const Qualifier in C
The qualifier const can be applied to the declaration of any variable to specify that its value will not be changed (which depends upon where const variables are stored, we may change the value of the const variable by using a pointer). The result is implementation-defined if an attempt is made to change a const. Using the const qualifier in C is a
7 min read