السلام عليكم
سعيد جداً بالانضمام الى هذا الموقع الرائع واتمنى ان اجد منكم من يساعدنا
turn = 0 // shared control variable while (turn != i); // CS turn = (turn + 1) % n;
`هذه الخوارزمية مطلوب مني اقوم بتحويلها الى thread باستخدام الجافا وحاولت كثيراً لكني لم افلح توصلت في الاخير الى هذا الكود لكنه مليء بالغباء للاسف الشديد
/*
* Mutual exclusion using thread
*/
class gV{
int turn=0;
}
class newThread extends Thread{
static int i;
int n=10;
newThread(gV obj){
this.i=obj.turn;
start();
}
public void run(){
while(obj.turn!=i&&obj.turn<n);
criticalSection(i);
obj.turn=(obj.turn+1);
i++;
}
public void criticalSection(int numOfProcess){
System.out.println("Process " + numOfProcess + " done!!");
}
}
class MutualExclusion{
public static void main(String args[]){
gV obj = new gV();
new newThread(obj);
}
}
هل يوجد احد يستطيع ان يساعدنا ويقلي ايش هي اخطائي وكيف اقدر اتخلص من هذه الاخطاء وشكراً


