registration
Are you an Employer?
List of Topics
Embedded Systems Interview Questions & Answers

Embedded Systems Interview Questions & Answers


Embedded Systems Interview Questions

Collapse all
  • What Is The Difference Between Embedded Systems And The System In Which Rtos Is Running?

    Embedded system is just combination of s/w and h/w that is some embedded system may have os some may not and rtos is an os.

                                                                      OR

    Embedded system can include RTOS and cannot include also. it depends on the requirement. if the system needs to serve only event sequentially, there is no need of RTOS. If the system demands the parallel execution of events then we need RTOS.

  • What Is Pass By Value And Pass By Reference? How Are Structure Passed As Arguments?

    The parameter to a function can be a copy of a value that is represented by variable or can be a reference to a memory space that stores value of variable. The former is referred to as pass by value and the latter is referred to as pass by reference. The difference is that when parameters are passed by value the changes made to the variable value within the function is not reflected in the caller function, but when passed as reference changes are reflected outside the called function. The structures are always passed by reference.

  • What Is Difference Between Using A Macro And Inline Function?

    The macro are just symbolic representations and cannot contain data type differentiations within the parameters that we give. The inline functions can have the data types too defined as a part of them. The disadvantage in using both is that the inclusion of condition checks may lead to increase in code space if the function is called many times.

  • What Is The Volatile Keyword Used For?

    The volatile keyword is used to represent variables that point to memory in other mapped devices. In such a case the value of the variable can be changed outside of a program. The compiler does not do additional optimizations to the code if there is volatile keyword.

  • What Are Hard And Soft Real Time Systems?

    The hard real time systems are the one that depend on the output very strictly on time. Any late response or delay cannot be tolerated and will always be considered a failure. The soft real time systems on the other are not very rigid as the hard real time systems. The performance of the system degrades with the lateness of response, but it is bearable and can be optimized to a certain level for reuse of the result.

  • What Is A Semaphore? What Are The Different Types Of Semaphore?

    The semaphore is an abstract data store that is used to control resource accesses across the various threads of execution or across different processes. There are two types of semaphores:
    • The binary semaphore which can take only 0,1 values. (used when there is contention for a single resource entity). 
    • The counting semaphore which can take incremental values to certain limit (used when number of resources is limited).

  • Write A Constant Time Consuming Statement Lot Finding Out If A Given Number Is A Power Of 2?

    If n is the given number, then the expression (n & (n-1)) = 0 gives the logical output depicting if it is a power of 2 or not, if (n & (n-1) == 0) printf (“The given number is a power of 2”);

  • What Are Recursive Functions? Can We Make Them Inline?

    The recursive functions refer to the functions which make calls to itself before giving out the final result. These can be declared as in-line functions and the compiler will allocate the memory space intended for the first call of the function.

  • What Is The Size Of The Int, Char And Float Data Types?

    The size of the char and int are always dependent on the underlying operating system or firmware. This is limited to the number of address lines in the address bus. The int usually takes up a value of 2 bytes or 4 bytes. The char can take up a space of 1 or 2 bytes. The float data type takes up a value of 4 bytes.

  • What Does Malloc Do? What Will Happen If We Have A Statement Like Malloc(sizeof(0));

    Malloc is the function that is used for dynamically allocating memory to the different variables. The malloc returns a memory pointer of void type (void *). The statement malloc(sizeof(0)) returns a valid integer pointer because sizeof(0) represents the size of memory taken up by the integer value of 0. The memory allocated by memory is not automatically cleaned up by the compiler after execution of the functions and should be cleaned up by the programmer using the free() function.

  • What Is Meant By A Forward Reference In C?

    The forward reference refers to the case when we point an address space of a smaller data type with a pointer of a bigger data type. This can be pictured as allocating memory in single bytes and accessing it with integer pointer as chunks of 4.

  • What Is The Order Of Calling For The Constructors And Destructors In Case Of Objects Of Inherited Classes?

    The constructors are called with base class first order and the destructors are called in the child first order. That is, the if we have 2 levels of inheritance A (base)-> B (inherit 1)-> C (inherit 2) then the constructor A is called first followed by B and C. The C destructor is called first followed by B and A.

  • Explain The Properties Of A Object Oriented Programming Language.

    • Encapsulation: The data that are related to the specific object are contained inside the object structure and hidden from the other entities of the environment.  
    • Polymorphism: The mechanism by which the same pointer can refer to different types of objects, which are basically linked by some generic commonality.
    •  Abstraction: Hiding the data and implementation details from the real objects. The framework of reference is still present to be used by the other objects.
    •  Inheritance: The way to take out the common features and have them as separate object entities only to be reused by the other objects in a modular fashion.
  • What Do You Mean By Interrupt Latency?

    Interrupt latency refers to the time taken for the system to start the handler for the specific interrupt. The time from the time of arrival of interrupt to the time it is being handled.

  • What Typecast Is Applied When We Have A Signed And An Unsigned Int In An Expression?

    The unsigned int is typecast into the signed value.

  • How Are Variables Mapped Across To The Various Memories By The C Compiler?

    The compiler maintains the symbol table which has the related information of all the variable names along with the length of the allocated space, the access unit length for the pointer (type of pointer) and the starting address of the memory space.

  • What Is A Memory Leak? What Is A Segmentation Fault?

    The memory leak refers to the uncleared memory may builds up across lifetime of the process. When it comes to a huge value system stalls its execution due to unavailability of the memory. The segmentation fault on the other hand refers to condition when our program tries to access a memory space that has already been freed up.

  • What Is Isr? Can They Be Passed Any Parameter And Can They Return A Value?

    ISR refers to the Interrupt Service Routines. These are procedures stored at specific memory addresses which are called when certain type of interrupt occurs. The ISRs cannot return a value and they cannot be passed any parameters.

  • A=7; B=8; X=a++-b; Printf("%d", X ); What Does This Code Give As Output?

    The compiler understands the statement expression a--b by taking off as much operators as it makes sense to a variable. So (a++) is taken as a parameter and then the expression becomes 8-8 which in turn gives the x value as 0. Thus the output value is 0.

  • What Are Little Endian And Big Endian Types Of Storage? How Can You Identify Which Type Of Allocation A System Follows?

    The little endian memory representation allocates the least address to the least significant bit and the big endian is where the highest significant bit takes up the least addressed memory space. We can identify the system’s usage by defining an integer value and accessing it as a character.

    int p=0x2; 
    if(* (char *) &p == 0x2) printf (“little endiann”); 
    else printf (“big endiann”);
  • What Is The Scope Of A Function That Is Declared As Static?

    The static function when declared within a specific module is scoped only in that module and can only be accessed from it.

  • What Is The Use Of Having The Const Qualifier?

    The const qualifier identifies a specific parameter or variable as read-only attribute to the function or to the entire program. This can come in handy when we are dealing with static data inside function and in a program.

  • Why Do We Need A Infinite Loop In Embedded Systems Development? What Are The Different Ways By Which You Can Code In A Infinite Loop?

    The infinite loops are coded in to give a delay or sleep to the program execution for a specific amount of clock ticks. They can be implemented as:

    while(;;); 
    for(); 
    (or) 
    Loop: 
    goto Loop;
  • What Is A 'volatile' Variable?

    Volatile is a keyword to specify the compiler that this variable value can change any time, so compiler should always read its value from its address, and not to use temporary registers to store its value and use in later part of the code. This is especially important to handle the memory mapped registers which are mapped as some variables or structures in embedded systems, such as hardware status registers etc, whose value can be changed anytime, depending on the hardware state.

    Examples of volatile variables are,
    • Hardware registers in peripherals (for example, status registers)
    • Non-automatic variables referenced within an interrupt service routine
    • Variables shared by multiple tasks in a multi-threaded application

  • Can A Volatile Be Constant?

    volatile const a;
    Yes it can be, it means that, it can be changes by hardware state change, but its read only register in hardware, so code should not try to modify it.

  • Can A Pointer Be Volatile ?

    Yes, although this is not very common. An example is when an interrupt service routine modifies a pointer to a buffer.

  • What Is A 'const' Variable?

    In simple terms 'const' means 'read only'. Its value is not changed by any part of the code executed. So compiler can optimize by taking this info, and also it will give warning when user try to change the value of this variable by mistake.

  • Which Is The Best Way To Write Loops?

    The best way is to write count down loops and compiler can generate better machine code for it than the count up loops. In count down at loop termination, it needs to generate one instruction (SUBS), which subtracts as well as check the zero flag, but in count up case it has to add and compare with a constant, which takes two instructions.

  • What Is Loop Unrolling?

    Small loops can be unrolled for higher performance, with the disadvantage of increased codesize. When a loop is unrolled, a loop counter needs to be updated less often and fewer branches are executed. If the loop iterates only a few times, it can be fully unrolled, so that the loop overhead completely disappears.

    int CountBitOne(uint n)
    {     
      int bits = 0;
        while (n != 0)
        {
            if (n & 1) bits++;
            n >> = 1;
        }
      return bits;
    }
     
    int CountBitOne(uint n)
    {
       int bits = 0;
        while (n != 0)
        {
        if (n & 1) bits++;
        if (n & 2) bits++;
        if (n & 4) bits++;
        if (n & 8) bits++;
        n >> = 4;
        }
      return bits;
    }
    
  • How Are Local And Global Variables Are Allocated By Compiler.

    Normally, cpu registers are allocated for local variables, but if the address of that local variable is used by some code, then it won’t allocate register but access from memory, thus result in un-optimized code. Gobal variables always use memory, so access is slower, so always use global only when it is absolutely necessary.

  • Which Is Better A Char, Short Or Int Type For Optimization?

    Where possible, it is best to avoid using char and short as local variables. For the types char and short the compiler needs to reduce the size of the local variable to 8 or 16 bits after each assignment. This is called sign-extending for signed variables and zero extending for unsigned variables. It is implemented by shifting the register left by 24 or 16 bits, followed by a signed or unsigned shift right by the same amount, taking two instructions (zero-extension of an unsigned char takes one instruction).

    These shifts can be avoided by using int and unsigned int for local variables. This is particularly important for calculations which first load data into local variables and then process the data inside the local variables. Even if data is input and output as 8- or 16-bit quantities, it is worth considering processing them as 32bit quantities

  • How To Reduce Function Call Overhead In Arm Based Systems

    •  Try to ensure that small functions take four or fewer arguments. These will not use the stack for argument passing. It will copy into registers.
    •  If a function needs more than four arguments, try to ensure that it does a significant amount of work, so that the cost of passing the stacked arguments is outweighed.
    •  Pass pointers to structures instead of passing the structure itself.
    •  Put related arguments in a structure, and pass a pointer to the structure to functions. This will reduce the number of parameters and increase readability.
    •  Minimize the number of long long parameters, as these take two argument words. This also applies to doubles if software floating-point is enabled.
    •  Avoid functions with a parameter that is passed partially in a register and partially on the stack (split-argument). This is not handled efficiently by the current compilers: all register arguments are pushed on the stack.
    •  Avoid functions with a variable number of parameters. Varargs functions.
  • What Is A Pure Function In Arm Terminology?

    Pure functions are those which return a result which depends only on their arguments. They can be thought of as mathematical functions: they always return the same result if the arguments are the same. To tell the compiler that a function is pure, use the special declaration keyword __pure.

    __pure int square(int x)
    {
        return x * x;
    }
  • What Are Inline Functions?

    The ARM compilers support inline functions with the keyword __inline. This results in each call to an inline function being substituted by its body, instead of a normal call. This results in faster code, but it adversely affects code size, particularly if the inline function is large and used often.

  • Infinite Loops Often Arise In Embedded Systems. How Does You Code An Infinite Loop In C?

    There are several solutions to this question. One is,

    while(1)
    {
    } 

    Other is using for loop, but here things are not pretty clear as to what is going on.

    for(;;)
    {
    }

    Even though both serve the same purpose, its always better to know why you are using the first or second. So when you are asked about such questions you must answer with confidence that both are right, and just matter which way you wish to code it, anyways finally compiler would optimize and generate the same code for it. So don’t ever say, I was taught to do it this way, and so never thought about the other ways.
    There is another way of doing it, i.e. by using goto statement, goto is very basic keyword, which is more like an assembly jump instruction, if one finds more comfortable with goto then possibly he works closely with assembly language, or with FORATN.

    loop:
    ...
    ...
    goto loop;
  • Data Declarations?

    Examples of data declarations:

    a) int a;
    An integer

    b) int *a;
    A pointer to an integer

    c) int **a;
    A pointer to a pointer to an integer

    d) int a[10];
    An array of 10 integers

    e) int *a[10];
    An array of 10 pointers to integers

    f) int (*a)[10];
    A pointer to an array of 10 integers

    g) int (*a)(int);
    A pointer to a function a that takes an integer argument and returns an integer

    h) int (*a[10])(int);
    An array of 10 pointers to functions that take an integer argument and return an integer

  • What Are The Uses Of The Keyword Static?

    •  A variable declared static within the body of a function maintains its value between function invocations .
    • A variable declared static within a module, (but outside the body of a function) is accessible by all functions within that module. It is not accessible by functions within any other module. That is, it is a localized global.
    •  Functions declared static within a module may only be called by other functions within that module. That is, the scope of the function is localized to the module within which it is declared.
  • Accessing Fixed Memory Locations?

    Embedded systems are often characterized by requiring the programmer to access a specific memory location. On a certain project it is required to set an integer variable at the absolute address 0x67a9 to the value 0xaa55. The compiler is a pure ANSI compiler. Write code to accomplish this task.

    This problem tests whether you know that it is legal to typecast an integer to a pointer in order to access an absolute location. The exact syntax varies depending upon one's style. However, I would typically be looking for something like this:

    int *ptr;
    ptr = (int *)0x67a9;
    *ptr = 0xaa55;  
    

    A more obscure approach is:

    *(int * const)(0x67a9) = 0xaa55;
  • Explain What Happens When Recursion Functions Are Declared Inline?

    Inline functions property says whenever it will called, it will copy the complete definition of that function. Recursive function declared as inline creates the burden on the compilers execution. The size of the stack may/may not be overflow if the function size is big.

  • Explain Scope Of Static Variables?

    • Static variables can only be accessed in the files were they are declared.
    • Static variable within the scope of a function store it's values in consecutive calls of that function.
    • Static functions can only be called within the file they are defined.
  • What Is Interrupt Latency?

    Interrupt latency refers to the amount of time between when an interrupt is triggered and when the interrupt is seen by software.

  • Explain Order Of Constructor And Destructor Call In Case Of Multiple Inheritance?

    constructors top-down, destructors bottom-up.
    eg:

    • in parent's constructor
    • in child's constructor
    • in grandchild's constructor
    • in grandchild's destructor
    • in child's destructor
    • in parent's destructor
  • Explain Difference Between Object Oriented And Object Based Languages?

    Object based languages doesn’t support Inheritance where as object oriented supports. c# is a object oriented language because it supports inheritance and asp.net is not a language it is a technology. If the language supports only 3 features i;e (data encapsulation, data abstraction and polymorphism).then it is said to be object based programming language. If the language supports all the 4 features i;e (encapsulation, abstraction, polymorphism and also inheritance ) then it is said to be object oriented programming language.

  • What Are The Advantages And Disadvantages Of Using Macro And Inline Functions?

    Advantage:
    Macros and Inline functions are efficient than calling a normal function. The times spend in calling the function is saved in case of macros and inline functions as these are included directly into the code.
    Disadvantage:
    Macros and inline functions increased the size of executable code.

  • Explain Why Cannot Arrays Be Passed By Values To Functions?

    Because in C when you say the name of the array it means the address of the first element.
    example :

    int a[];
    func (a);
    int func(int a[]);
    

    In this when you call the function by passing the argument a actually &a[0](address of first element) gets passed. Hence it is impossible to pass by value in C.

     

  • Explain What Is Interrupt Latency? How Can We Reduce It?

    Interrupt latency is the time required to return from the interrupt service routine after tackling a particular interrupt. We can reduce it by writing smaller ISR routines.

  • Explain What Are The Different Qualifiers In C?

    1) Volatile:
    A variable should be declared volatile whenever its value could change unexpectedly. In practice, only three types of variables could change:
    ► Memory-mapped peripheral registers
    ► Global variables modified by an interrupt service routine
    ► Global variables within a multi-threaded application

    2) Constant:
    The addition of a 'const' qualifier indicates that the (relevant part of the) program may not modify the variable.

  • Explain What Are The 5 Different Types Of Inheritance Relationship?

    5 level types are as under:

    • single: B derived from A.
    • multilevel: derived from B and B derived from A.
    • multiple: C derived from A and B.
    • Hierarchical: B derived from A and C derived from A.
    • hybrid: combination of above types.
  • Explain What Will This Return Malloc(sizeof(-10))?

    It will return a 4 byte address value.
    Because -10 is a signed integer(varies from compiler to compiler).

  • Explain Can Structures Be Passed To The Functions By Value?

    Yes structures can be passed to functions by value. Though passing by value has two disadvantages:
    1) The charges by the calling function are not reflected.
    2) It’s slower than the pass by reference function call.

  • Explain Can We Have Constant Volatile Variable?

    Const and volatile keywords should not be used together because both are opposite in nature. A variable is declared as "const" means it's value is not able to be changed but if it is declared as "Volatile" then it is not under control.

  • Explain What Are The Different Storage Classes In C?

    Four types of storage classes are there in c.
    1.Auto
    2.Register
    3.Static
    4.Extern or Global

  • Explain What Is Forward Reference W.r.t. Pointers In C?

    Pointer use's to reference to value a into int a=10 to memory add this value and 10 is add p value added this data in memory location for p.

  • How Is Function Itoa() Written In C?

    #include<stdlib.h>
    #include<stdio.h>
    int main()
    {
    int n = 6789;
    char p[20];
    itoa(n,s,10);
    printf("n=%d,s=%s",n,s);
    return 0;
    } 
  • How To Define A Structure With Bit Field Members?

    You can define structure bit field members with Dot operators.

    EXAMPLE:

    #include <stdio.h>
    int main()
    {
    Struct bit_field
    {
    Int x.4; // it allocates only 4 bits to x
    Char C.6; // it allocates only 6 bits to C;
    };
    return 0;
    } 
  • What Is The Difference Between Fifo And The Memory?

    Fifo(First In Last Out) is a memory structure where data can be stored and retrieved (in the order of its entry only). This is a queue,wheras Memory is a storage device which can hold data dynamically or at any desired locations and can be retrieved in any order.

  • Is It Necessary To Start The Execution Of A Program From The Main() In C?

    "Normally you are at liberty to give functions whatever names you like, but "main"' is special - your program begins executing at the beginning of main. This means that every program must have a main somewhere." 

  • What Is An Anti Aliasing Filter? Why Is It Required?

    Anti aliasing filter reduces errors due to aliasing. If a signal is sampled at 8 kS/S, the max frequency of the input should be 4 kHz. Otherwise, aliasing errors will result. Typically a 3.4kHz will have an image of 4.6 khz, and one uses a sharp cut off filter with gain of about 1 at 3.4kHz and gain of about 0.01 at 4.6 kHz to effectively guard against aliasing. Thus one does not quite choose max frequency as simply fs/2 where fs is sampling frequency. One has to have a guard band of about 10% of this fmax, and chooses max signal frequency as 0.9*fs/2.

  • How To Implement A Fourth Order Butterworth Lp Filter At 1khz If Sampling Frequency Is 8 Khz?

    A fourth order Butterworth filter can be made as cascade of two second order LP filters with zeta of 0.924 and 0.383. One can use a bilinear transformation approach for realizing second order LP filters. Using this technique described well in many texts, one can make two second order LP filters and cascade them.

  • Is 8085 An Embedded System?

    its not a embedded system...because it will be a part of a embedded system and it does not work on any software.

  • What Is The Role Of Segment Register?

    In the x86 processor architecture, memory addresses are specified in two parts called the segment and the offset. One usually thinks of the segment as specifying the beginning of a block of memory allocated by the system and the offset as an index into it. Segment values are stored in the segment registers. There are four or more segment registers: CS contains the segment of the current instruction (IP is the offset), SS contains the stack segment (SP is the offset), DS is the segment used by default for most data operations, ES (and, in more recent processors, FS and GS) is an extra segment register. Most memory operations accept a segment override prefix that allows use of a segment register other than the default one.

  • What Type Of Registers Contains An (intel) Cpu?

    Special function registers like accumulator, Program controller(PC),data pointer(DPTR),TMOD and TCON (timing registers),3 register banks with r0 to r7,Bit addressable registers like B.

  • What Is Plc System?

    Programming logical control system.

  • What Is Difference Between Micro Processor & Micro Controller?

    •  Microprocessor is a manager of the resources (I/O, Memory) which lie out-side of its architecture.
    • Micro-controllers have I/O, Memory etc. built into it and specially designed for Control applications.
  • Can We Use Semaphore Or Mutex Or Spin Lock In Interrupt Context In Linux Kernel?

    We cannot sleep in interrupt context so semaphores and mutex can't be used. Spinlocks can be used for locking in interrupt context.

  • Dma Deals With Which Address (physical/virtual Addresses)?

    DMA deals with Physical addresses.

    • Only when CPU accesses addresses it refers to MMU(Memory Management Unit) and MMU converts the Physical address to Virtual address.
    • But, DMA controller is a device which directly drives the data and address bus during data transfer. So, it is purely Physical address. (It never needs to go through MMU & Virtual addresses).
    • That is why when writing the device drivers, the physical address of the data buffer has to be assigned to the DMA.
  • What Is Dirac Delta Function And Its Fourier Transform And Its Importance?

    • Dirac delta is a continuous time function with unit area and infinite amplitude at t=0 the fourier transform of dirac delta is 1.
    • using dirac delta as an input to the system, we can get the system response. it is used to study the behavior of the circuit.
    • we can use this system behavior to find the output for any input.
  • What Is The Difference Between Testing And Verification Of Vlsi Circuit?

    • Verification is a front end process and testing is a post silicon process.
    • Verification is to verify the functionality of the design during the design cycle.
    • Testing is finding manufacturing faults.
  • While Writing Interrupt Handlers (isr), Which Are Points Needed To Be Considered?

    Avoid sleep, use GFP_ATOMIC instead of GFP_KERNEL in kmalloc.

  • Explain Can Microcontroller Work Independently?

    Obviously, it can work independently. But to see the output we need certain output devices like LED, Buzzer can be connected to check its functionality. Without the help of any o/p device connected we can check the functionality of Microcontroller.

  • What Is Watchdog Timer?

    A watchdog timer (or computer operating properly timer) is a computer hardware timing device that triggers a system reset if the main program, due to some fault condition, such as a hang, neglects to regularly service the watchdog. The intention is to bring the system back from the hung state into normal operation.

  • What Is Semaphore?

    In computer science, a semaphore is a protected variable or abstract data type which constitutes the classic method for restricting access to shared resources such as shared memory in a parallel programming environment. A counting semaphore is a counter for a set of available resources, rather than a locked/unlocked flag of a single resource.

  • What Is Mutex?

    Mutual exclusion (often abbreviated to mutex) algorithms are used in concurrent programming to avoid the simultaneous use of a common resource, such as a global variable, by pieces of computer code called critical sections.

  • Can Structures Be Passed To The Functions By Value?

    yes structures can be passed by value. But unnecessary memory wastage.

  • Why Cannot Arrays Be Passed By Values To Functions?

    When a array is passed to a function, the array is internally changed to a ‘pointer’. And pointers are always passed by reference.

  • Advantages And Disadvantages Of Using Macro And Inline Functions?

    Advantage: Macros and Inline functions are efficient than calling a normal function. The times spend in calling the function is saved in case of macros and inline functions as these are included directly into the code.
    Disadvantage: Macros and inline functions increased the size of executable code.

  • Difference In Inline Functions And Macro

    •  Macro is expanded by preprocessor and inline function are expanded by compiler.
    •  Expressions passed as arguments to inline functions are evaluated only once while _expression passed as argument to inline functions are evaluated more than once.
    • More over inline functions are used to overcome the overhead of function calls.
    • Macros are used to maintain the readability and easy maintenance of the code.
  • What Happens When Recursion Functions Are Declared Inline?

    It is illegal to declare a recursive function as inline. Even a function is declared as inline compiler judges it to be inline or not. Many compilers can also inline expand some recursive functions; recursive macros are typically illegal.

  • Scope Of Static Variables?

    Scope of static variable is within the file if it is static global. Scope of static variable is within the function if variable is declared local to a function. But the life time is throughout the program.

  • What Is A Inode?

    In computing, an inode is a data structure on a traditional Unix-style file system such as UFS. An inode stores basic information about a regular file, directory, or other file system object.

  • Explain The Working Of Virtual Memory?

    Virtual memory is a computer system technique which gives an application program the impression that it has contiguous working memory (an address space), while in fact it may be physically fragmented and may even overflow on to disk storage. Systems that use this technique make programming of large applications easier and use real physical memory (e.g. RAM) more efficiently than those without virtual memory.

  • What Is Concurrency? Explain With Example Deadlock And Starvation.

    Concurrency is nothing but execution of different transactions simultaneously on one single resource.
    Dead lock :
    A group of threads are waiting for resources held by others in the group. None of them will ever make progress.
    Example :
    An example of a deadlock which may occur in database products is the following. Client applications using the database may require exclusive access to a table, and in order to gain exclusive access they ask for a lock. If one client application holds a lock on a table and attempts to obtain the lock on a second table that is already held by a second client application, this may lead to deadlock if the second application then attempts to obtain the lock that is held by the first application.
    Starvation :
    A thread may wait indefinitely because other threads keep coming in and getting the requested resources before this thread does. Note that resource is being actively used and the thread will stop waiting if other threads stop coming in.
    Example :
    High priority thread:

    while(1);

    if the system is priority based system then low priority thread never gets a chance.