Threads Join
נתונה השאלה הבאה:
for (int i = 0; i <5; i++)
{Globalvar += 1;}}void main(){Thread x = new Thread(Func);Thread y = new Thread(Func);x.Start();x.Join();y.Start();Write(Globalvar);}What is the output?The question was about thread concurrency.Two threads run the same code, that increments global variable 10 times each.If both threads enter the critical section at the same time then final result would be 10 (instead of 20), but it can be even less than 10.
למה שיהיה קטע קריטי? אם משתמשים בJoin אז קודם thread x רוץ ורק שיסיים thread y ירוץ.
אשמח להסבר לגבי התשובה שמופיעה בתרגיל...
תודה
נתונה השאלה הבאה:
public void Func(){for (int i = 0; i <5; i++)
{Globalvar += 1;}}void main(){Thread x = new Thread(Func);Thread y = new Thread(Func);x.Start();x.Join();y.Start();Write(Globalvar);}What is the output?The question was about thread concurrency.Two threads run the same code, that increments global variable 10 times each.If both threads enter the critical section at the same time then final result would be 10 (instead of 20), but it can be even less than 10.
למה שיהיה קטע קריטי? אם משתמשים בJoin אז קודם thread x רוץ ורק שיסיים thread y ירוץ.
אשמח להסבר לגבי התשובה שמופיעה בתרגיל...
תודה