Question: ( 2 0 points ) The following multi - threaded code snippets are supposed to add amount to a global variable balance . For each
points The following multithreaded code snippets are supposed to add amount to a global variable balance For each of the snippets, determine if race conditions can occur. If there is a race condition, use a scenario of two threads A and B executing the same code to show an example of a race condition. Also, lets assume the operations associated with a code statement are atomic. Example: void deposit int amount int tmp balance; line tmp tmp amount; line balance tmp; line Answer: Race condition. For example, when A B A A B BA means thread A executing line void deposit int amount int tmp amount; line lock; line tmp tmp balance; line unlock; line balance tmp; line void deposit int amount int tmp amount; line lock; line tmp tmp balance; line balance tmp; line unlock; line void deposit int amount int tmp &balance; line lock; line tmp tmp amount; line unlock; line balance tmp; line void deposit int amount int tmp &amount; line lock; line tmp tmp balance; line unlock; line balance tmp; line
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
