This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Deadlock { | |
public Deadlock( ) { | |
Mutex mutex[] = new Mutex[4]; | |
for ( int i = 0; i < 4; i++ ) | |
mutex[i] = new Mutex( ); | |
A threadA = new A( mutex ); | |
B threadB = new B( mutex ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Deadlock { | |
public Deadlock( ) { | |
Mutex mutex[] = new Mutex[4]; | |
for ( int i = 0; i < 4; i++ ) | |
mutex[i] = new Mutex( ); | |
A threadA = new A( mutex ); | |
B threadB = new B( mutex ); | |
C threadC = new C( mutex ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Provide a quick debugger of the TCBs in queue | |
// Format of output is = Q[i]-> { [p,t] [p,t] [p,t] ... } | |
private void dumpQueue(int time) { | |
int N; | |
if (DEBUG) { | |
System.out.print("T("+time+"): "); | |
// scan through each multilevel queue | |
for (int i=0; i < 3; i++) { | |
// how many TCBs are in queue | |
N = queue[i].size(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ThreadDriver { | |
public static void main( String[] args ) { | |
String args[2]; | |
args[0] = "ping"; args[1] = "10000"; | |
new PingPong( args ).start( ); | |
args[0] = "PING"; args[1] = "90000"; | |
new PingPong( args ).start( ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PingPong extends Thread { | |
private String word; | |
private int loop; | |
public PingPong( String[] args ) { | |
word = args[0]; | |
loop = Integer.parseInt( args[1] ); | |
} | |
public void run( ) { | |
for ( int j = 0; j < 100; j++ ) { | |
SysLib.cout( word + " " ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PingPong extends Thread { | |
private String word; | |
private int loop; | |
public PingPong( String[] args ) { | |
word = args[0]; | |
loop = Integer.parseInt( args[1] ); | |
} | |
public void run( ) { | |
for ( int j = 0; j < 100; j++ ) { | |
SysLib.cout( word + " " ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ----------------------- Start Debugger Method --------------------------- | |
// Provide a simple debugger of the TCBs in queue | |
// Format of output is = Q[]-> { [p,t] [p,t] [p,t] ... } | |
// Where p = Process ID | |
// t = Thread ID | |
// ------------------------------------------------------------------------- | |
private void dumpQueue(int time) { | |
if (DEBUG) { | |
System.out.print("\nT("+time+"): "); | |
// how many TCBs are in queue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Disk disk = new Disk( 1000 ); | |
// a disk read operation: | |
while ( disk.read( blockId, buffer ) == false ) | |
; // busy wait | |
while ( disk.testAndResetReady( ) == false ) | |
; // another busy wait | |
// now you can access data in buffer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.lang.reflect.*; | |
import java.io.*; | |
public class Kernel { | |
// Interrupt requests | |
public final static int INTERRUPT_SOFTWARE = 1; // System calls | |
public final static int INTERRUPT_DISK = 2; // Disk interrupts | |
public final static int INTERRUPT_IO = 3; // Other I/O interrupts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Disk disk = new Disk( 1000 ); | |
SyncQueue ioQueue = new SyncQueue( ); | |
... | |
... | |
// a disk read operation: | |
while ( disk.read( blockId, buffer ) == false ) { | |
ioQueue.enqueueAndSleep( 1 ); // relinquish CPU to another ready thread | |
// now check to ensure disk is not busy | |
while ( disk.testAndResetReady( ) == false ) | |
ioQueue.enqueueAndSleep( 2 ); // relinquish CPU to another ready thread |
OlderNewer