CC150 16 chapter operating system

There are more fundamental problems in CC150, so it would be good if I can go through the problems in CC150 and go over the basic things on this book. It would definitely help me a lot. The first thing I should mention that there is no book book like bible. So just To know that Why you would read this book, cause you want to find a job. And you should know that This is not you would do in the future.


The chapter 16 Threads and Locks. The things about operating system.


Operating System


1 threads. There are tow ways to implement the thread in tJava./

The first is to implment runnable interface. and inorder to implement the runnanle interface, you have to define the run function int the runnable interface. And then the function should return the value. In the end, this can call some method.

public class my example implements Runnanle{
	publilc int count = 0;
	public void run(){
		System.out.println("runnable String");
		try{
			while(count , 5){
				Thread.sleep(500);
				count++;
			}
		}
		catch(InterruptedException exc){\
			System.out.println("there is a interrupt that causes the exception");
		}
	}
}


anohter way to do that is to extends Thread.

public class ThreadExample extends Thread{
	iint count = 0;
	//This is to run the method , this is another structure that the thread can run in java. that is very important.
	public void run(){
	}
}


Then because the threads in a given process shsare the sane memory space, which is both a positive or a negative, when different threads go to the same resource, then this space may be changed by different threads which we do not want this effect. Also We do not want this


The key word for a method to be synchronized is synchronized

public synchronized void foo{

}

so for the same object then the method can not run at the same time, cuase it is different threads can not access to the same space, however for the different methods in different objects the same method can run the same time and it does not interfere anymore cause it can run individually.


the last thing to mention that we also can lock the value is basically called in one class.


public class lockedATM{
	private Lock lock;
	private int balance = 500;
	
	public void withdraw(int value){
		lock.lock(); 	//for this part, if the lock is locked then the program can not access to the value in this class.
		int tem = balance;
	}
}

And there is a situation that can cause the dead lock. for different process. waiting for each other and in the waiting graph there is a waiting circle then this is called dead lock, in order to avoid the dead lock, what we need to do is to have one of the four conditions that the deadlock doesnot met. if we break one of these then the dead lock would disappear.

1 multual exclusion

2 hold and wait'

3 no preemption

4 circular wait.


The next thing I want to do is to finish the homework at the end of the chapter:

發佈了123 篇原創文章 · 獲贊 0 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章