Question: This diagram represents a Linux process and its stack memory layout. The process has two threads, Thread 1 and Thread 2 , each with its
This diagram represents a Linux process and its stack memory layout. The process has two threads, Thread and Thread each with its own stack, sharing the same address space. Thread is executing and performing a function call, pushing data onto its stack. Simultaneously, Thread is also executing and making its own function call, pushing data onto its stack threads are using the same function with different arguments.
What will happen if both threads modify a global variable within the function?
Pick ONE option
The global variable will be overwritten with the value from the thread that called the function last.
The global variable will be unaffected, as each thread has its own stack, isolating their modifications.
The final value will be unpredictable since the order of their executions cannot be determined.
The global variable will automatically be protected, and only one thread can modify it at a time.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
