Thread: Help!!!!!!!!!!!
View Single Post
Old May 2nd, 2008, 4:03 PM   #3
nannu
Newbie
 
Join Date: Apr 2008
Posts: 19
Rep Power: 0 nannu is on a distinguished road
Re: Help!!!!!!!!!!!

Can someone please assist me in how I should approach this problem. Its for my operating class.

Write a program with two threads sharing a variable. One threads repeatedly
subtracts a constant values from the shared variable, while the second
repeatedly adds the same value. If the number of transactions that the threads
execute is the same, then the value of the shared variable after the threads
complete should be the same as the initial value – that is assuming access to the
shared variable is mutually exclusive.

First write the program without any code to protect the critical section, and test it
with a large number of iterations (hopefully the final value should deviate from
the original). Then incorporate a mutex lock into the solution and test it again.
That should ensure data consistency, and the program output should confirm it.

Last edited by nannu; May 2nd, 2008 at 4:16 PM.
nannu is offline   Reply With Quote