KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a global shared variable and that is being updated 5 times by each of the 5 threads spawned. As per my understanding the increment operation is consisting of 3 instructions load reg, M inc reg store reg, M So I want to ask that in this scenario what would be the maximum and minimum value given arbitrary interleaving in the 5 threads. So according to me the maximum value will be 25 ( I am 100% sure that it can be more than 25) and the minimum value is 5. But I am not so sure on minimum value. Can it be less that 5 in some arbitrary interleaving ? Any inputs will be greatly appreciated. /* Global Variable */ int var = 0; /* Thread function */ void thread_func() { for(int c = 0; c < 5; c++) var++; }
Tags (comma-separated)
Save Edits
Cancel