Question
In a multithreaded environment, which of the following
synchronization mechanisms is used to prevent race conditions?ÂSolution
A semaphore is a synchronization mechanism that is crucial for controlling access to shared resources in a multithreaded environment. It serves as a signaling mechanism that can be used to prevent race conditions, which occur when multiple threads attempt to modify shared data simultaneously, leading to unpredictable outcomes. Semaphores maintain a count of available resources and ensure that only a certain number of threads can access the critical section of code at any given time. When a thread wants to enter a critical section, it checks the semaphore's value; if it is greater than zero, the thread decrements it and proceeds; otherwise, it is blocked until the semaphore is released by another thread. This prevents multiple threads from executing critical sections concurrently, thereby eliminating race conditions and ensuring data consistency. Option B (Fork) - Fork is used to create new processes, not for synchronizing access to shared resources. Option C (Signal) - Signals are used for inter-process communication but do not provide the same level of resource control as semaphores. Option D (Context Switch) - Context switching refers to the operating system's ability to switch between processes and threads, which does not inherently prevent race conditions. Option E (Stack) - A stack is a data structure and does not serve any synchronization purpose in multithreading.
An amount of Rs. ‘y’ was invested on (R-2)% per annum on simple interest and at the end of 6 years an amount of Rs. 23100 was obtained as an interes...
Simple interest on a sum at 8% p.a. for 3 years is ₹1920. Find the principal and amount.
A borrowed Rs. 9500 from B for his business. How much amount A will return to B at the end of 36 months such that the sum was borrowed at simple interes...
Rs. 5,500 is invested in scheme ‘A’ offering simple interest of 15% p.a. and Rs. 8,000 in scheme ‘B’ offering simple interest of 5% p.a. What is...
The simple interest received on a certain sum is Rs. 250 less than the sum invested. If the sum was invested at 15% p.a. for 4 years, then find the simp...
An amount of Rs. 2400 is invested at an annual compound interest rate of 20%, while another amount of Rs. 1600 is invested simultaneously at an annual s...
A sum of Rs. 2800 is invested at simple interest for 2 years. If the rate interest for first year is 10% p.a. while 18% p.a. for second year, then find ...
Akshay invested Rs. 2240 in two schemes P and Q in the respective ratio of 9:7. Scheme P and Q are offering simple interest at the rate of 10% per annum...
A man invested a certain amount of sum at 11% per annum simple interest and earned an interest of Rs. 2200 after 2 years. If the same amount is i...
- Hitesh divided Rs. 20,100 into two portions. He invested the first portion at 6% simple interest per annum for 5 years, and the second portion at 20% simpl...