我目前正在使用操作系统,我们的老师为我们的实验室分配了此问题,但他的帮助不是很大。因此,我需要显示带有信号量的死锁的基本示例,并且我的输出需要演示死锁的发生。我假设他的意思是如果发现我的例外情况。这和我已经接近了。
import java.util.concurrent.Semaphore;
public class deadlockTest2
{
private Semaphore sem1=new Semaphore(1);
private Semaphore sem2=new Semaphore(1);
private int num;
public deadlockTest2(int random)
{
num=random;
}
public void run()
{
try
{
sem1.acquire();
}
catch (InterruptedException e)
{
System.out.println("I am deadlocked");}
}
public static void main(String[] args)
{
deadlockTest2 tester=new deadlockTest2(5);
deadlockTest2 tester2=new deadlockTest2(20);
tester.run();
tester2.run();
}
}
Run Code Online (Sandbox Code Playgroud)
〜
〜
上午我还差得远?我一直在阅读材料,但没有完全掌握。我想我不明白什么是过程。有人请帮忙。